Let us c solution

 [c]

Write a program for a matchstick game being played between the 
computer and a user.Your program should ensure that the computer
always wins.Rules for the game are as follows:-
--There are 21 match sticks
--The computer asks the player to pick 1,2,3 or 4 matchstick.
--After the person picks the computer does its picking.
--whenever is forced to pick up the last matchstick loses the game.  */

#include<stdio.h>
int main()
{
	int m=21,p,c;
	while(1)
	{
		printf("\nNo.of matches left=%d\n",m);
		printf("Pick up 1,2,3 or 4 matches:");
		scanf("%d",&p);
		if(p>4||p<1)
		continue;
		m=m-p;
		printf("No.of match left=%d\n",m);
		c=5-p;
		printf("Out of which computer picked up=%d\n",c);
		m=m-c;
		if(m==1)
		{
			printf("Number of matches left=%d\n",m);
			printf("You lost the game !!\n");
		}
	}
	return 0;
}

Post a Comment

0 Comments