C c

Published on November 4th, 2011 | by Decoding

9

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>
#define MAGIC 42
int main()
{
char a,c,x;
int i,count,j=0;
x=MAGIC;

printf(“n n ttttt  Think of any two digit no. n Then add both digits together and substract the result from the original no.”);
sleep(4);
printf(” n n t For ex. 32ntt3+2=5ntt 32-5=27  would be your no. then”);

printf(“nnnt Now remember the symbol that would correspond to your no.nnPress y if you wish to continue,…… “);

scanf(“%c”,&a);
if(a==’y’)
{

for(i=32;i<=132;i++,j++)
{
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);
}

/*    printf(“nnLoading “);
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;
}


About the Author



9 Responses to Smart ‘C’ reading Minds…..

  1. Ankush Tale says:

    Can anyone suggest why the ” Loading” part doesn’t get compiled ?

  2. Check headers … maybe use #include

  3. mayur404 says:

    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.

    • Ankush Tale says:

      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..?

  4. mayur404 says:

    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

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Back to Top ↑