Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Name: stickpuzzle.c
- Copyright:
- Author: Mr.Kindle
- Date: 06-12-22 23:35
- Description: Given 21 Matchsticks and 2 users, A and B (computer and user respectively).
- Users and computer both can pick matchsticks not more than four at a time. The one who is forced to
- pick the last matchstick loses.Make an algorithm so that computer always win.
- Given that user pickup the stick first.
- */
- #include<stdio.h>
- int main()
- {
- int stick,u,c;
- stick = 21;
- while(stick)
- {
- printf("number of stick: %d\n",stick);
- if(stick == 1)
- { printf("\n*****************************\n\n");
- printf("\nYOU HAVE TO PICK UP THE LAST STICK\n");
- printf("YOU LOOSE BETTER LUCK NEXT TIME\n");
- break;
- }
- printf("You pickup stick (MAXIMUM 4): ");
- scanf("%d",&u);
- if(u > 4)
- {
- printf("\nPlease pickup less than 5 stick only: \n\n\n");
- continue;
- }
- stick = stick-u;
- /*Now computer will pickup the stick*/
- c = 5-u;
- printf("computer picked up: %d\n",c);
- stick = stick - c;
- }
- }//main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement