Introduction
Repeat the mat_add problem from request 3. Write a program called mat_add.c that asks the user for 2 matrices A, and B, and displays their sum, C.
- Name your executable mat_add.out
- All numbers entered will be integers
- All matrices will be valid
- Changes There is now no max size for each matrix. You must dynamically allocate space for all arrays used.
This means you must use malloc to create your arrays. - int A[rows][cols] will not be accepted
- Each row of the matrix will be entered 1 line at a time
- The formula for calculating C[i][j] is C[i][j]=A[i][j]+B[i][j]
- Examples:
1
2
3
4
5
6
7
8
9
10
11Please enter the number of rows: 2
Please enter the number of columns: 2
Enter Matrix A
1 2
3 4
Enter Matrix B
100 200
200 400
A + B =
101 202
203 404
1 | Please enter the number of rows: 2 |
Requirement 2
Write a program to implement the game connect-n. Connect-n is like Connect-4 except instead of having the board be a constant 6 X 7 we will allow the user to enter the size of the board they would like to play on. In addition we will also allow the user to choose how many pieces in a row are necessary to win. The game is played as follows. Two players take turns dropping their pieces into a column until either player gets N of their pieces in a row either horizontally, vertically, or diagonally, or until their or no more spaces to play.
Your program must accept 3 command line parameters in this order: number of rows, number of columns, number of pieces in a row to win, If the user does not enter enough arguments or enters too many arguments your program should tell them the proper usage of your program and terminate.
You may find the exit function helpful.
The user should be allowed to create an unwinable game.
For example a board that is 3 X 3 but requires 4 pieces in a row to win.
Your program should not allow the user to make an impossible play but should continue to ask the user for a play until a valid play is entered
Invalid plays consist of plays made outside the board or in to columns that are already full.
The token used to represent Player 1 is X
The token used to represent Player 2 is O, a capitol oh and not a zero
After the game is over the winner should be declared or if there is no winner a tie should be declared
You must split your code up into at least 2 files.
I personally had 4 separate c files
You must submit a make file named Makefile that when run compiles your program
The executable created by your make file should be named connectn.out
Hints
This is your first “large” program. It took me around 300 lines of code to complete. You will want to break your problem down into many small manageable functions to make the problem easier to deal with.
Examples
1 | ../connectn.out |
1 | ../connectn.out 1 2 3 4 5 |
1 | ../connectn.out 3 3 3 |
1 | ../connectn.out 1 2 3 |