Question
I'm having very hard time figuring out how I would determine if an array with the same number of rows and columns has all different
I'm having very hard time figuring out how I would determine if an array with the same number of rows and columns has all different values or not (so whether if its a distinct matrix or not). I also need to be able to sort the same array using row wise approach and calculate and print its transpose. All of this should be done in C. Heres my code so far, the bolded code is me trying to determine if it has different values or not, its not working. Please help me determine if an array with the same number of rows and columns has all different values or not, sort the array using row wise approach and calculate its transpose:
#include
void main() { int mat[MAX][MAX]; int i, j, m, n; int size; int rowsum, columnsum, diagonalsum; int k; int magic = 0; printf("Enter the # of rows and columns of the square matrix (must be same number): "); scanf("%d %d", &m, &n); if(m==n) { printf("Enter the elements of matrix "); for(i=0; i printf(" Given matrix is a magic square matrix"); } else { printf(" Please enter the square matrix order(m=n) "); } int all_distinct = 1; int count, l; for (i = 0; i < mat[i]; i++) { for(j = 0; j < mat[j]; j++) { count = 0; for(k = 0; k < mat[i]; k++) { for(l = 0; l < mat[j]; l++) { if(mat[k][l] == mat[i][j]) { count++; } } } if(count != 1) { all_distinct = 0; } } } if(all_distinct) { printf("All elements in the array are distinct "); } else { printf("All elements in the array are not distinct "); } return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started