Matchstick Game in C with Source Code

The 21 Matchstick Game in C was made with the help of the computer language C. There is a total of 21 matchsticks available before the start of the game. To begin, we present the user with a choice between making one, two, three, or four selections each match.

When the user has finished making their selection, the computer will then make the ultimate determination (same rules apply to the computer i.e., it can pick either 1 or 2 or 3 or 4 matches per pick). The important thing to remember is that the computer’s pick is never more than 5 points higher than the user’s choice.

The while loop’s condition 1 assures that the loop will continue to execute until a break statement is met within the loop, which will then cause the execution of the loop to be terminated. The while(1) construct is considered to be an endless loop (unless we have some ways to break out of the loop programmatically).

Anyway if you want level up your knowledge in programming especially C/C++ Programming Language, try this new article I’ve made for you Best C Projects with Source Code for Beginners Free Download 2020.

Make sure that you have Code Blocks or another platform capable of running C installed on your computer if you want to play this Matchstick Game on it. For your convenience, a free copy of the Matchstick Game project is available below; simply scroll down and click the download button.

Project Name : Matchstick Game
Project Platform :C/C++
Programming Language Used:C Programming Language
Developer Name
IDE Tool (Recommended):Dev-C++/Codeblocks
Project Type :Desktop Application
Database:Stores data in .DAT file
Matchstick Game in C with Source Code Information

Matchstick Game Project in C Steps On How To Run The Project

Time needed: 5 minutes.

Here’s the step’s on how to run a Matchstick Game in C with Source Code.

  • Step 1: Extract file.

    Next, after you finished download the source code, extract the zip file.
    Extract file for Matchstick Game in C with Source Code

  • Step 2: Open CodeBlocks

    After that, After extracting the zip file, open your “CodeBlocks IDE”.
    Open Code blocks Apps for Extract file for Matchstick game in C with Source Code

  • Step 3: Open Project.

    Then, open file tab and Open File after that open folder MATCHSTICK-GAME-IN-C then click the “main“.

    Open file for Matchstick Game in C with Source Code

  • Step 4: Run Project

    Lastly, Open build tab and select build and run or you can use key F9.

  • Step 5: The actual code.

    Finally, You are free to copy the given source code below or download the downloadable source code given.

This Matchstick Game C was build and run under Code::Blocks IDE.

  • Function of variables use in this game.
int matchNumber = 21, player, computer;
  • Function to create a main window .
int main()
    int matchNumber = 21, player, computer;

        printf("\nNumber of Match sticks left = %d\n", matchNumber);
        printf("Pick 1 or 2 or 3 or 4 matches\n");
        scanf("%d", &player);

        if(player > 4 || player < 1)

        matchNumber = matchNumber - player;

        printf("Number of matches left = %d\n", matchNumber);

        computer = 5 - player;

        printf("out of which computer picked up %d\n", computer);

        matchNumber = matchNumber - computer;

        if(matchNumber == 1)
            printf("\nNumber of matches left = %d\n", matchNumber);
            printf("You lost the Game\n");
  • Output:

Downloadable Source Code


This Matchstick Game Project in C with Source Code is just a project that was produced for the sole aim of fulfilling academic requirements. Specifically for a project for the semester, a Matchstick Game was developed in the C programming language.

By conveying general information that can be put to use and is practical in nature regarding C, it is intended to provide novices with a good understanding of programming small to large projects.

You are able to download this application and alter it to meet the needs of your customers; but, given that this is a student project, you can not truly anticipate it to have a functioning rate of one hundred percent.


If you have any questions or suggestions about Matchstick in C Source Code, please feel free to leave a comment below.

2 thoughts on “Matchstick Game in C with Source Code”

Leave a Comment