Hey you :) get ready for binary magic,
I have written a C program that will tell you the number which u r thinking of.
Just go through this C program.
------------------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
main()
{
char ans;
int i,arr[5],number=0;
clrscr();
printf("THINK OF ANY NUMBER BETWEEN 1 AND 31 INCLUSIVE!\n\n");
//Take inputs from user.
for(i=0;i<5;i++)
{
printf("FIRST ROW : 3 1 5 7 9 11 13 15 17 19 21 23 25 27 29 31");
printf("\nSECOND ROW : 6 3 2 7 10 11 14 15 18 19 22 23 26 27 30 31");
printf("\nTHIRD ROW : 4 5 6 7 15 13 14 12 20 21 22 23 28 29 30 31");
printf("\nFOURTH ROW : 8 9 10 11 12 13 14 15 24 25 26 27 28 29 30 31");
printf("\nFIFTH ROW : 31 17 18 19 20 21 22 23 26 25 24 27 28 29 30 16");
printf("\n\nJUST KEEP THINKING AND TELL, IS THE NUMBER PRESENT IN THE ROW %d ? (Y/N) :", (i+1));
fflush(stdin);
scanf("%c",&ans);
if((ans=='y')||(ans=='Y'))
arr[i]=1; // store 1 for ans:Y ()
else
arr[i]=0; // store 0 for ans:n (No) or char other than Y/y
clrscr();
}
for(i=0;i<5;i++)
{
number=number+(arr[i]*power(i));
}
printf("\n\nGET READY FOR ANSWER! CLOSE YOUR EYES FOR FIVE SECONDS ... ");
delay(2000); // Wait for two seconds
// countdown ;) for answer
for(i=5;i>0;i--)
{
printf("%d\b",i);
delay(1000); //Wait for 1 second.
}
clrscr();
printf("\n\nNUMBER YOU ARE THINKING OF IS : %d = ;-) ",number);
getch();
return(0);
}
// function that returns 2 raised to 'n' (powof2 in this case)
int power(int powof2)
{
int j,a=1;
for(j=0;j<powof2;j++)
{
a=2*a;
}
return(a);
}
Copy and paste this code in Turbo C or any other C compiler.
Run this code and enjoy.
Please let me know if you get any errors or wrong answers .....
0 comments :
Post a Comment