answersLogoWhite

0


Best Answer

-There are 21 matchsticks.

-Whoever is forced to pick up the last matchstick loses the game.

So the last one is special, so it's all about how to get rid of 20 matches in pairs of turns.

-The computer asks the player to pick 1, 2, 3 or 4 matchsticks.

So if we reduce the total by 5 each round, the sequence will go

21 16 11 6 1

In effect, whatever number the user picks (n), the computer picks 5-n

'''#include'''

main()

'''{'''

'''int matchsticks=21, user, computer;

printf("Do not enter Invalid Numbers.\nNumbers above 4 are invalid.");

printf("\nIf you do so, the computer automatically wins.");

'''while (matchsticks>=1)

'''{'''

printf("\nNumber of matchsticks available right now is %d.", matchsticks);

printf("\n\nYour Turn...\n\n\n");

printf("\nPick up the matchstick(s)-- (1-4): ");

scanf ("%d", &user);

'''if (user>4)

'''{'''

printf("Invalid Selection");

'''break;

'''}'''

computer=5-user;

printf("\nComputer's Turn..\n" );

printf("\nComputer chooses:%d", computer);

matchsticks=matchsticks-user-computer;

'''continue;

'''if(matchsticks==1)

'''break;

'''}'''

matchsticks--;

printf("\nComputer Wins");

'''}'''

'''''''''''''''''''''

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program for a matchstick game being played between the computer and a user What if your program should ensure that the computer always wins Rules for the game are as follows?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is a series of instructions or commands that a computer follows used to create software?

program development


What is the difference between computer programsand computer applications?

An application is a program


What is the difference between an algorithm and a computer program?


What is the difference between program and software?

Program is a set of instruction of a computer to perform. Software is the various kind of program that is used to operate computer smoothly.


What is the relationshjip between a computer program and an algorithm?

A computer program can use a pre-programmed Algorith to calculate what you want it to calculate.


How is the maars taught to perform its task?

it's not actually 'taught'. The scientists write a computer program to tell the rover what to do - and send the program by radio to Mars. The rover receives the program, and follows the instructions.


The gateway between the user and the computer as well as between the application program and the computer system's hardware is the?

Correct Answer: Operating System


How is the maars robot taught to perform its task?

It's not actually 'taught'. The scientists write a computer program to tell the rover what to do - and send the program by radio to Mars. The rover receives the program, and follows the instructions.


What is a set of computer instructions that carries out a task on the computer?

A set of instructions that run on a computer that enables it to execute a specific task is called a program. Computer programs use several different types of calculating to make the computer do what the user wants it to do. One example is binary code programming.


What is the difference between a computer program and a computer?


What is the difference between a sprite and an object?

a sprite is a computer program that moves.


Difference between computer program and package?

There are fundamental similarities and difference between computational programming and packages. A computer program are the set of instructions behind a specific application or software. A package is set of software programs.