Question: Use the code skeleton on the next page to write a C program that allows the user to create any square matrix (a 2D arrays
Use the code skeleton on the next page to write a C program that allows the user to create any square matrix (a 2D arrays with the same number of rows and columns), for instance, a square matrix of size 5 is a 2d array of 5 rows and 5 columns. Your program should:
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.
Note: the code skeleton below:
#include#define MAX 100 void setMatrixData(int numOfRows, int mat[][numOfRows]){ // provide the implementation } void printMatrixData(int numOfRows, int mat[][numOfRows]){ // provide the implementation } int isMagicSquare(int numOfRows, int mat[][numOfRows]){ // provide the implementation return 1; // if the matrix is a magic square } int isDistinctSquare(int numOfRows, int mat[][numOfRows]){ // provide the implementation return 1; // if the matrix has no duplicates all values are unique } int main() { int matrix[MAX][MAX]; int numOfRows; do{ printf("Please enter the number of rows of your square matrix: "); scanf("%d", &numOfRows); }while(numOfRows < 1 || numOfRows > 100); setMatrixData(numOfRows, matrix); if(isMagicSquare(numOfRows, matrix)){ printf("Your matrix is a magic square "); }else{ printf(" your matrix is NOT a magic square "); } if(isDistinctSquare(numOfRows, matrix)){ printf("Your matrix is a distinct square "); }else{ printf(" your matrix is NOT a distinct square "); } printMatrixData(numOfRows, matrix); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
