Guest User

Untitled

a guest
Dec 12th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. int main() {
  3. int A[50][50];
  4. int i, j, N;
  5. int rowColDiff, diagonalDiff;
  6.  
  7. printf("Enter the N of the matrix NxN:\n");
  8. scanf("%d", &N);
  9.  
  10. printf("Enter the elements of matrix \n");
  11. for(i=0; i<N; i++) {
  12. for(j=0; j<N; j++) {
  13. scanf("%d", &A[i][j]);
  14. }
  15. }
  16.  
  17. printf("\n\nMATRIX is\n");
  18. for(i=0; i<N; i++) {
  19. for(j=0; j<N; j++) {
  20. printf("%3d\t", A[i][j]);
  21. }
  22. printf("\n");
  23. }
  24.  
  25. diagonalDiff = rowColDiff = 0;
  26. for(i=0; i<N; i++) {
  27. for(j=0; j<N; j++) {
  28. rowColDiff += A[i][j] - A[j][i];
  29. if(i==j) {
  30. diagonalDiff += A[i][j] - A[i][N-1-j];
  31. }
  32. if(rowColDiff) {
  33. printf("\nGiven matrix is not a magic square matrix");
  34. return 0;
  35. }
  36. }
  37. }
  38.  
  39. if(!diagonalDiff)
  40. printf("\nGiven matrix is a magic square matrix");
  41.  
  42. return 0;
  43. }
Add Comment
Please, Sign In to add comment