C languageC SolutionChapter 4Programming

Q6 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 matchsticks. – The computer asks the player to pick 1, 2, 3, or 4 matchsticks. – After the person picks, the customer does its picking. – Whoever is forced to pick up the last matchstick loses the game.

Program: 99

Write a c 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 matchsticks.
  • The computer asks the player to pick 1, 2, 3, or 4 matchsticks.
  • After the person picks, the customer does its picking.
  • Whoever is forced to pick up the last matchstick loses the game.

Output:

 Total Match Sticks: 21
 Pick up the match sticks between (1 to 4): 1
 Computer picks up the 4 match sticks.
 Total Match Sticks: 16
 Pick up the match sticks between (1 to 4): 2
 Computer picks up the 3 match sticks.
 Total Match Sticks: 11
 Pick up the match sticks between (1 to 4): 3
 Computer picks up the 2 match sticks.
 Total Match Sticks: 6
 Pick up the match sticks between (1 to 4): 4
 Computer picks up the 1 match sticks.
 You have been lost via computer.

Lokesh Kumar

Being EASTER SCIENCE's founder, Lokesh Kumar wants to share his knowledge and ideas. His motive is "We assist you to choose the best", He believes in different thinking.

4 thoughts on “Q6 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 matchsticks. – The computer asks the player to pick 1, 2, 3, or 4 matchsticks. – After the person picks, the customer does its picking. – Whoever is forced to pick up the last matchstick loses the game.

  • if(user_choice>4)
    {
    printf(“Invalid Entry”);
    break;
    }

    don’t you think this is wrong.

    Reply
  • sorry may mistake i got it.

    Reply
  • can you explain. how it’s wrong?

    Reply
    • Yusuf Jamal

      if(user_choice > 4 && user_choice < 1);
      {
      Printf(“Invalid Entry”);
      break;
      }

      This is the right code.
      It will work definitely.

      Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.