fork download
  1. #include <stdio.h>
  2. void main()
  3. {
  4. int i, j, flag=0, m, n;
  5. printf("Enter the order of the matrix(in row×column format):");
  6. scanf("%d×%d", &m, &n);
  7. int mat[m][n];
  8. printf("\nEnter the elements:\n");
  9. for(i=0;i<m;i++)
  10. {
  11. for(j=0;j<n;j++)
  12. scanf("%d ", &mat[i][j]);
  13. printf("\n");
  14. }
  15. if(m==n)
  16. {
  17. for(i=0;i<m;i++)
  18. {
  19. for(j=0;j<n;j++)
  20. {
  21. if(i!=j)
  22. {
  23. if(mat[i][j]==0)
  24. {
  25. flag=0;
  26. continue;
  27. }
  28. else
  29. {
  30. flag=-1;
  31. break;
  32. }
  33. }
  34. }
  35. if(flag==-1)
  36. break;
  37. }
  38. if(flag==0)
  39. printf("\nIt is a diagonal matrix");
  40. else
  41. printf("\nIt is not a diagonal matrix") ;
  42. }
  43. else
  44. printf("\nIt is not a diagonal matrix");
  45. }
  46.  
Success #stdin #stdout 0s 5472KB
stdin
2 2
1 0
0 1
stdout
Enter the order of the matrix(in row×column format):
Enter the elements:



It is not a diagonal matrix