Last active
March 30, 2021 07:05
-
-
Save jagdish4501/82f22b5825b10bbad95f44b4f4e480af to your computer and use it in GitHub Desktop.
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: 1− There are 21 matchsticks. − The computer asks the player to pick 1, 2, 3, or 4 matchsticks. − After the person picks, the computer does its picking. − Whoever is force…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
int match_stick = 21, user_choice, computer_choice; | |
printf("total number of match stick=%d\n", match_stick); | |
while (match_stick >= 1) | |
{ | |
printf("enter your chioce (1, 2,3 or 4)="); | |
scanf("%d",& user_choice); | |
if (user_choice > 4) | |
{ | |
printf("you enter wrong!\n "); | |
break; | |
} | |
computer_choice = 5 - (user_choice); | |
// ***** ***** ***** ***** * this is the set of for wining the game for computer | |
// i.e if user take any nuber between 1 to 4 and compter take remainig in the set of 5 stick | |
printf("choice taken by computer =%d\n", computer_choice); | |
match_stick = match_stick - (computer_choice + user_choice); | |
if (match_stick == 1) | |
{ | |
printf("you have lost the game and compuetr wins the game\n "); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment