Question

Q1) Write a C function that allows the user to initialize a Tic-Tac-Toe board. The board...

Q1) Write a C function that allows the user to initialize a Tic-Tac-Toe board. The board is a 2D array of size 3x3. The function will set an id for each cell of the board starting from 1 and stop at 9. The function prototype is ​void​​ ​​InitializeBoard​​(​​int​​ m, ​​int​​ n , ​​char​​ board[][n])

void​​ ​​InitializeBoard​​(​​int​​ m, ​​int​​ n , ​​char​​ board[][n])​​{

​​int​​ c =​​1​​; ​

for​​(​​int​​ i =​​0​​; i<m; i++){ ​​

for​​(​​int​​ j=​​0​​; j< n; j++){

board[i][j] = c+​​'0'​​;

c++;

}

}

}

NOTE:​​ The answer for Q1 is given to you as a help to get you start  


Q2) Write a C function that allows the user to print a Tic-Tac-Toe board. The function prototype is void​​ ​​PrintBoard​​(​​int​​ m, ​​int​​ n, ​​char​​ board[][n])​​.  

0 0
Add a comment Improve this question Transcribed image text
Answer #1
void PrintBoard(int m, int n, char board[][n]) {
    for(int i = 0; i < m; i++) {
        for(int j = 0; j < n; j++) {
            printf("%c ", board[i][j]);
        }
        printf("\n");
    }
}
Add a comment
Know the answer?
Add Answer to:
Q1) Write a C function that allows the user to initialize a Tic-Tac-Toe board. The board...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C programming language Purpose The purpose of this assignment is to help you to practice working...

    C programming language Purpose The purpose of this assignment is to help you to practice working with functions, arrays, and design simple algorithms Learning Outcomes ● Develop skills with multidimensional arrays ● Learn how to traverse multidimensional arrays ● Passing arrays to functions ● Develop algorithm design skills (e.g. recursion) Problem Overview Problem Overview Tic-Tac-Toe (also known as noughts and crosses or Xs and Os) is a paper-and-pencil game for two players, X and O, who take turns marking the...

  • In the C++ programming language write a program capable of playing 3D Tic-Tac-Toe against the user....

    In the C++ programming language write a program capable of playing 3D Tic-Tac-Toe against the user. Your program should use OOP concepts in its design. Use Inheritance to create a derived class from your Lab #9 Tic-Tac-Toe class. You can use ASCII art to generate and display the 3x3x3 playing board. The program should randomly decide who goes first computer or user. Your program should know and inform the user if an illegal move was made (cell already occupied). The...

  • In traditional Tic Tac Toe game, two players take turns to mark grids with noughts and...

    In traditional Tic Tac Toe game, two players take turns to mark grids with noughts and crosses on the 3 x 3 game board. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row in the game board wins the game. Super Tic Tac Toe game also has a 3 x 3 game board with super grid. Each super grid itself is a traditional Tic Tac Toe board. Winning a game of Tic...

  • My homework is to write a tic tac toe function, this code isn't working and I...

    My homework is to write a tic tac toe function, this code isn't working and I can not find the error. It prints the board and accepts user input just fine, the only problem is the checkBoard function. I can not get it to return a value(player win) to end the while loop. #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> int checkBoard(char board[3][3]) {    int i, j;    for (i = 0; i < 3; i += 1) {        if...

  • JAVA TIC TAC TOE - please help me correct my code Write a program that will...

    JAVA TIC TAC TOE - please help me correct my code Write a program that will allow two players to play a game of TIC TAC TOE. When the program starts, it will display a tic tac toe board as below |    1       |   2        |   3 |    4       |   5        |   6                 |    7      |   8        |   9 The program will assign X to Player 1, and O to Player    The program will ask Player 1, to...

  • Tic-Tac-Toe (arrays and multidimensional arrays) C++ Write an interactive program that plays tic-tac-toe. Represent the board...

    Tic-Tac-Toe (arrays and multidimensional arrays) C++ Write an interactive program that plays tic-tac-toe. Represent the board as a 3 X 3 character array. Initialize the array to blanks and ask each player in turn to input a position. The first player's position is marked on the board with a O and the second player's position is marked with an X. Continue the process until a player wins or the game is a draw. To win, a player must have 3...

  • In Java create a program where a user plays Tic Tac Toe against the computer. Create...

    In Java create a program where a user plays Tic Tac Toe against the computer. Create a class TicTacToe that will enable you write a program to play Tic-Tac-Toe. The class contains a private 3x3 two-dimensional array. Use an enum type to represent the value in each cell of the array. The enum’s constants should be named X, O, and EMPTY (for a position that does not contain an X or O). The constructor should initialize the board elements to...

  • Implement a tic-tac-toe game. At the bottom of these specifications you will see a template you...

    Implement a tic-tac-toe game. At the bottom of these specifications you will see a template you must copy and paste to cloud9. Do not change the provided complete functions, or the function stub headers / return values. Currently, if the variables provided in main are commented out, the program will compile. Complete the specifications for each function. As you develop the program, implement one function at a time, and test that function. The provided comments provide hints as to what...

  • 18. Tic-Tac-Toe Game rite a program that allows two players to play a game of tic-tac-toe. Use di...

    18. Tic-Tac-Toe Game rite a program that allows two players to play a game of tic-tac-toe. Use dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that does the following: Write . Displays the contents of the board array. . Allows player 1 to select a location on the board for an X. The program should ask the...

  • Can somebody help me with this coding the program allow 2 players play tic Tac Toe....

    Can somebody help me with this coding the program allow 2 players play tic Tac Toe. however, mine does not take a turn. after player 1 input the tow and column the program eliminated. I want this program run until find a winner. also can somebody add function 1 player vs computer mode as well? Thanks! >>>>>>>>>>>>>Main program >>>>>>>>>>>>>>>>>>>>>>> #include "myheader.h" int main() { const int NUM_ROWS = 3; const int NUM_COLS = 3; // Variables bool again; bool won;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT