WELCOME IN THE SEA OF C

Here you find some good quality programs.
If any one want any type of help in C and C++ then you can mail me.
Google

Wednesday, March 12, 2008

A CHALLENGING GAME:

There are 21 matchsticks, you have to choose matchsticks between 1 to 4 and then computer will choose, and the one who takes the last matchstick will lose........just try it!!!!!!

"/" is used instead of "<" and ">".
#include/stdio.h/
#include/conio.h/
void game(int);
void check(int);

void main()
{
static int s=21;
clrscr();
printf("NO of matchstick is %d\n",s);
game(s);

getch();
}

void game(int s)
{

int n=1,m=3,x=4,y=2,p,choice;
printf("\nenter your choice between 1 and 4 is \n");
scanf("%d",&p);
s=s-p;
if(s>1 && s<=5)
{
check(s);
printf("\n1.want to play again");
printf("\n2.Exit\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
main();
break;
case 2:
exit();
}
}
else
if(p==1)
{
printf("computer choice is %d",x);
s=s-x;
printf("No of Matchstick left is %d",s);
if(s>0)
{
game(s);
}
}

if(p==4)
{

printf("computer choice is %d",n);
s=s-n;
printf("No of Matchstick left is %d",s);
if(s>0)
{
game(s);
}
}
else
if(p==2)
{

printf("computer choice is %d",m);
s=s-m;
printf("No of Matchstick left is %d",s);
if(s>0)
{
game(s);
}}

if(p==3)
{

printf("computer choice is %d",y);
s=s-y;
printf("No of Matchstick left is %d",s);
if(s>0)
{
game(s);
}}
else
printf("enter correct choice");
}


void check(int s)
{

switch(s)
{
case 5:
printf("Computer choice is 4 \n");
printf("Computer Wins");
printf("\n You Lose");
break;

case 4:
printf("Computer choice is 3 \n");
printf("Computer Wins");
printf("\n You Lose");
break;

case 3:
printf("Computer choice is 2 \n");
printf("Computer Wins");
printf("\n You Lose");
break;

case 2:
printf("Computer choice is 1 \n");
printf("Computer Wins");
printf("\n You Lose");
break;
}
}