Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main() {
- int A[50][50];
- int i, j, N;
- int rowColDiff, diagonalDiff;
- printf("Enter the N of the matrix NxN:\n");
- scanf("%d", &N);
- printf("Enter the elements of matrix \n");
- for(i=0; i<N; i++) {
- for(j=0; j<N; j++) {
- scanf("%d", &A[i][j]);
- }
- }
- printf("\n\nMATRIX is\n");
- for(i=0; i<N; i++) {
- for(j=0; j<N; j++) {
- printf("%3d\t", A[i][j]);
- }
- printf("\n");
- }
- diagonalDiff = rowColDiff = 0;
- for(i=0; i<N; i++) {
- for(j=0; j<N; j++) {
- rowColDiff += A[i][j] - A[j][i];
- if(i==j) {
- diagonalDiff += A[i][j] - A[i][N-1-j];
- }
- if(rowColDiff) {
- printf("\nGiven matrix is not a magic square matrix");
- return 0;
- }
- }
- }
- if(!diagonalDiff)
- printf("\nGiven matrix is a magic square matrix");
- return 0;
- }
Add Comment
Please, Sign In to add comment