fork download
  1. #include <stdio.h>
  2.  
  3. int matrixCompare(int, int *, int *);
  4. void printMatrixCompare(int, int *, int *);
  5.  
  6. int main(void)
  7. {
  8. int matrixA[3][3] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  9. int matrixB[3][3] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  10. int matrixC[3][3] = { 1, 4, 3, 4, 5, 6, 7, 8, 9 };
  11.  
  12. printMatrixCompare(3, *matrixA, *matrixB);
  13. printMatrixCompare(3, *matrixA, *matrixC);
  14. printMatrixCompare(3, *matrixB, *matrixA);
  15. printMatrixCompare(3, *matrixB, *matrixC);
  16. printMatrixCompare(3, *matrixC, *matrixA);
  17. printMatrixCompare(3, *matrixC, *matrixB);
  18.  
  19. //2d matrix of size 3*3
  20. //give 2 matrices of size 2*2 as example
  21.  
  22. // int matrixF[3][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
  23. // int matrixG[3][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 10 } };
  24.  
  25. // 0 1 2
  26. // 0 1 2 3
  27. // 1 4 5 6
  28. // 2 7 8 9
  29.  
  30.  
  31. return 0;
  32. }
  33.  
  34. int matrixCompare(int pSize, int *matrixA, int *matrixB)
  35. {
  36. int i;
  37. for (i = 0; i < pSize*pSize; i++)
  38. {
  39.  
  40. if (*matrixA!=*matrixB)
  41. {
  42. if (*matrixA < *matrixB)
  43. return -1;
  44. else
  45. return 1;
  46. }
  47. matrixA++;
  48. matrixB++;
  49. }
  50. return 0;
  51. }
  52.  
  53.  
  54. void printMatrixCompare(int pSize, int *matrixA, int *matrixB)
  55. {
  56. int result = matrixCompare(pSize, matrixA, matrixB);
  57. if (result == 0)
  58. puts("Both matrices are equal.");
  59. if (result == -1)
  60. puts("matrixA is smaller than matrixB");
  61. if (result == -1)
  62. puts("matrixA is greater than matrixB");
  63. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Both matrices are equal.
matrixA is smaller than matrixB
matrixA is greater than matrixB
Both matrices are equal.
matrixA is smaller than matrixB
matrixA is greater than matrixB