Lab 2: Matrix
Preliminaries
Create and svn add a lab2 directory inside your repostiory.
To pass in a 2D array to a function you don't need to specify the first dimension but you do need to specify the second dimension.
For Example:
int foo(int a[][4],int rowSize, int colSize){ .... }
The Matrix Menu
Write a program that has the following menu:Welcome to the Matrix Program (1): Read in a 5x5 matrix. (2): Print the row totals in the matrix. (3): Print the column totals in the matrix. (4): Find a repeated number. (5): Quit. Option #:
You need to implement a program that performs all the tasks listed in the menu. If the user does not enter in a valid integer between 1 and 5 then the menu should keep prompting the user to enter in a integer that is between 1 and 5.
After each task has been performed the user should be presented with the matrix menu again. Information about each task is listed below.
Task #1: Read in a Matrix
Write a function that reads in a 5x5 array of integers:Enter row 1: 9 3 -1 0 13 Enter row 2: 74 5 -5 2 1 Enter row 3: 2 -11 6 23 1 Enter row 4: 15 2 3 2 47 Enter row 5: 7 101 2 6 2 Array Entered.
You are NOT allowed to have scanf read in 5 integers (i.e. scanf("%d%d%d%d%d",...) think of a way to read in each integer one at a time using scanf). The prompts must look excatly like the example shown.
Task #2: Row totals
Write a function that prints the row totals for the matrix entered.For example, If the matrix was the following:
Row 1: 9 3 -1 0 13 Row 2: 74 5 -5 2 1 Row 3: 2 -11 6 23 1 Row 4: 15 2 3 2 47 Row 5: 7 101 2 6 2
Then the function should print out the following to the user:
Row totals: 24 77 21 69 118
Task #3: Column totals
Write a function that prints the column totals for the matrix entered.For example, If the matrix was the following:
Row 1: 9 3 -1 0 13 Row 2: 74 5 -5 2 1 Row 3: 2 -11 6 23 1 Row 4: 15 2 3 2 47 Row 5: 7 101 2 6 2
Then the function should print out the following to the user:
Column totals: 107 101 5 33 64
Task #4: Repeated Number
Write a function that prompts the user for two integers. The first integer will represent a number that the function will search for within the matrix. The second number will represent how many times the first number must and only occur within the matrix. The function should display a message indiciating that the first number was found with the number of occurrences specified by the second number, or was not found with those number of occurrences.For example, If the matrix was the following:
Then running task #4 from the prompt menu should perform the following:Row 1: 9 3 -1 0 13 Row 2: 74 5 -5 2 1 Row 3: 2 -11 6 23 1 Row 4: 15 2 3 2 47 Row 5: 7 101 2 6 2
orEnter in a number: 2 Enter in the number of times the 2 should occur in the matrix: 5 Found the number 2 in the matrix 5 times.
Enter in a number: 2 Enter in the number of times the 2 should occur in the matrix: 2 Did not find the number 2 in the matrix 2 times.
Put all these functions in a file called lab2.c
Once completed, commit the file to your repositoryYou have completed the lab! Call me over to show me your lab for credit.