Smart ‘C’ reading Minds…..
Try this program….. It has a simple logic, but preety good to fool the innocent minds….. Just each time you run the program change the no. in #define MAGIC to any no. between 35-46. And do note that its a gcc compiler program. Make corresponding changes to use it in tc. Enjoy coding ……. #include<stdio.h> printf(“n n ttttt Think of any two digit no. n Then add both digits together and substract the result from the original no.”); printf(“nnnt Now remember the symbol that would correspond to your no.nnPress y if you wish to continue,…… “); scanf(“%c”,&a); for(i=32;i<=132;i++,j++) /* printf(“nnLoading “); }
#define MAGIC 42
int main()
{
char a,c,x;
int i,count,j=0;
x=MAGIC;
sleep(4);
printf(” n n t For ex. 32ntt3+2=5ntt 32-5=27 would be your no. then”);
if(a==’y’)
{
{
c=i;
if((i-32)%9==0&&(i-32)%5==0) printf(“%d=%c n”,j,x);
else if((i-32)%9==0) printf(“%d=%c t”,j,x);
else if((i-32)%5==0) printf(“%d=%cn”,j,c);
else printf(“%d=%ct”,j,c);
}
for(i=1;i<=9;i++)
{
sleep(1);
printf(“. “);
} *I have a problem with this. Why isn’t it working ? */
sleep(9);
printf(“n It was t %c n”,x);
return 0;
}
9 Responses to Smart ‘C’ reading Minds…..
Leave a Reply


Can anyone suggest why the ” Loading” part doesn’t get compiled ?
are bhai……that loading part is working on my P.C correctly!!!!
That which the program has ?
Then may be usleep() function should be used instead sleep in VIM…
Check headers … maybe use #include
try this ankush,
int i;
printf(“LOADING”);
for(i=0;i<10;i++)
{
printf(".");
delay(500);
}
for delay() function include header dos.h in your program.
i.e #include
it worked on my pc but not tried on linux.
I wished to write a code such that it changes the value of MAGIC each time it executes which otherwise has to be done manually….
Is it possible..?
hey…i got a way to do that……
just write randomize();// include stdlib.h for it
x=rand();//include time.h for it
so each time u compile different random values will be assigned to x!!!!
This works on TC…try it on linux!!!!
Thanx dennis, . . .
Would try it soon
x=rand() is just not sufficient,
as we require a range from 35-46 we have to give some condition.
because rand() gives random numbers between 0 to 234 i guess.
here is a small code i wrote for this:
int x;
x=rand();
while(x is less than 35 or x is greater than 46)
{
x=rand();
}
MAGIC=x;
but the drawback is that you will get a random number between 35-46, suppose for example 40, but next time you run the same code you will again get the same number 40. so its of of no use.
now there is another way: by using srand();
by using srand(); random number generated can be reinitialized.
here is the code that will give you random number between 35-46 everytime you run the program:
code:
int x;
time_t t;
srand((unsigned) time(&t));
x=rand();
while(x is less than 35 or x is greater than 46)
{
x=rand();
}
MAGIC=x;
for srand(); initialize #include and for time initialize #include