Question: #include #define MAX 100 void setMatrixData(int numOfRows, int mat[][numOfRows]){ // provide the implementation int cols; printf(Please enter number of rows and cols for the matrix:
#include
void setMatrixData(int numOfRows, int mat[][numOfRows]){ // provide the implementation
int cols; printf("Please enter number of rows and cols for the matrix: "); scanf("%d %d", &numOfRows, &cols);
int i, j; printf("Enter your matrix "); for(i=0;i void printMatrixData(int numOfRows, int mat[][numOfRows]){ // provide the implementation int cols,i,j; printf(" Here is your matrix: "); for(i=0;i } int isMagicSquare(int numOfRows, int mat[][numOfRows]){ // provide the implementation int sum, sum1, sum2,i,j,cols; int flag = 0; sum = 0; for (i = 0; i < numOfRows; i++) { for (j = 0; j < cols; j++) { if (i == j) sum = sum + mat[numOfRows][cols]; } } //testing Rows for (i = 0; i < numOfRows; i++) { sum1 = 0; for (j = 0; j < cols; j++) { sum1 = sum1 + mat[numOfRows][cols]; } if (sum == sum1) flag = 1; else { flag = 0; break; } } //testing Columns for (i = 0; i < numOfRows; i++) { sum2 = 0; for (j = 0; j< cols; j++) { sum2 = sum2 + mat[cols][numOfRows]; } if (sum == sum2) flag = 1; else { flag = 0; break; } } if (flag == 1){ return 1; // if the matrix is a magic square printf("Magic square it is."); } else{ return 0; printf(" No Magic square"); } } int isDistinctSquare(int numOfRows, int mat[][numOfRows]){ // provide the implementation int m, n, count = 0,i,j,cols; for(i = 0; i < numOfRows; i++) { for(j = 0; j < cols; j++) { count = 0; for(m = 0; m < numOfRows; m++) { for (n = 0; n < cols; n++) { if(mat[m][n] == mat[i][j]) { count++; } } } if(count != 1) { return 0; } } } return 1; // if the matrix has no duplicates all values are unique } void SortRowWise(int numOfRows, int mat[][numOfRows]){ // provide the implementation int k,a,i,j,cols; printf("The row-wise sorted matrix "); for (i = 0; i < numOfRows; i++) { for (j = 0; j < cols; j++) { for (k =(j + 1); k < cols; k++) { if (mat[i][j] > mat[i][k]) { a = mat[i][j]; mat[i][j] = mat[i][k]; mat[i][k] = a; } } } } for (i = 0; i < numOfRows; i++) { for (j = 0; j < cols; j++) { printf("%d", mat[i][j]); } printf(" "); } } void GetTranspose(int numOfRows, int mat[][numOfRows], int tran[][numOfRows]){ // provide the implementation int i,j,cols; for(i=0; i int main() { int matrix[MAX][MAX]; int transpose[MAX][MAX]; int numOfRows; printf("Done..."); } Hi, above is a main function calling 6 fuctions. I have already finished the six function that will be called, but I have trouble writing the main to let them all work as a whole. Could you help me to write the main? You can change the six functions too. Thank you. The six functions included all those seven abilities below. all codes are in C language 1. Allow the user to set the size (order) of the square matrix 2. Set the values of the matrix 3. Print the square matrix on the screen in a tabular format 4. Check and print if the square matrix is a magic square or not. 5. Check and print if the square matrix is a distinct matrix or not. 6. Sort the square matrix using row-wise approach. 7. Calculate the transpose matrix for the square matrix
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
