C > Beginners Lab Assignments
Puzzle--finding the number
Puzzle--finding the number #include
#include
#include
#include
#include
int mx,my,ans=0,p=4; screen(); void button(); /* The main logic lies in displaying the numbers in the screen The numbers are placed corresponding to their binary value EX:In case of 14(binary equivalent is 01110).Therefore it will be placed in 2,3 & 4 screen */ int s1[]={16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31}; int s2[]={8,9,10,11,12,13,14,15,24,25,26,27,28,29,30,31}; int s3[]={4,5,6,7,12,13,14,15,20,21,22,23,28,29,30,31}; int s4[]={2,3,6,7,10,11,14,15,18,19,22,23,26,27,30,31}; int s5[]={1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31}; int a1,a2,a3,a4,a5; void main() { int gd=DETECT,gm; initgraph(&gd,&gm,"c:\tc\bgi"); mouseini(); showmp(); action(); } action() { int ans=0; char st[10]; initialscreen(); while(1) { /* The X & Y coordinate of each function is calculated with respect to mx "maximum of x value" & my "maximum of y value" */ if(click((mx/4)+95,(my/4)+100,(mx/4)+235,(my/4)+140,"Play..")==0) { a1=screen(s1,16); a2=screen(s2,16); a3=screen(s3,16); a4=screen(s4,16); a5=screen(s5,16); ans=a1+a2+a3+a4+a5; result(ans); getch(); exit(); } } } initialscreen() { mx=getmaxx(),my=getmaxy(); setmp(); setfillstyle(1,7); bar(mx/4,my/4,3*mx/4,3*my/4); setcolor(WHITE); line(mx/4,my/4,3*mx/4,my/4); line(mx/4,my/4,mx/4,3*my/4); setcolor(BLACK); line(mx/4,3*my/4,3*mx/4,3*my/4); line(3*mx/4,my/4,3*mx/4,3*my/4); setcolor(RED); outtextxy((mx/4)+40,(my/4)+30,"THINK A NUMBER BETWEEN 1-31"); button((mx/4)+95,(my/4)+100,(mx/4)+235,(my/4)+140,"Play.."); } screen(int *scr,int num) { int a,i,x1,y1; char st[10]; mx=getmaxx(),my=getmaxy(); setmp(); setfillstyle(1,7); bar(mx/4,my/4,3*mx/4,3*my/4); setcolor(WHITE); line(mx/4,my/4,3*mx/4,my/4); line(mx/4,my/4,mx/4,3*my/4); setcolor(BLACK); line(mx/4,3*my/4,3*mx/4,3*my/4); line(3*mx/4,my/4,3*mx/4,3*my/4); setcolor(RED); outtextxy((mx/4)+9,(my/4)+5,"TELL ME WHETHER THE NUMBER IS PRESENT?"); button((3*mx/4)-40 ,(3*my/4)-20,(3*mx/4)-5 ,(3*my/4)-5,"yes"); button((3*mx/4)-80 ,(3*my/4)-20,(3*mx/4)-45 ,(3*my/4)-5,"no"); x1=(mx/4)+80; y1=(my/4)+65; for(i=0;i
x1 && x
y1 && y
C Codes
Beginners
C on Unix
Code Snippets
Data Structures
File Operations
Games Graphics
Gnu-Linux
Hardware
Mathematics
Miscellaneous
Small Programs
Sorting