fork download
  1. // Online C compiler to run C program online
  2. #include <stdio.h>
  3. int add(int matrixA, int matrixB);
  4. int sub(int matrixA, int matrixB);
  5. int product(int matrixA, int matrixB);
  6. int trans(int matrixA, int matrixB);
  7. int main() {
  8. int matA [3] [3];
  9. //taking input from user
  10. printf("Enter values for a matrix A(3x3) :\n");
  11. for (int i = 0; i < 3 ; i++) {
  12. for(int j = 0 ; j < 3 ; j++) {
  13. printf("row %d and column %d: ", i + 1 , j+1);
  14. scanf("%d", &matA[i][j]);
  15. }
  16. }
  17. int matB [3] [3];
  18. printf("\nEnter values for matrix B(3x3) :\n");
  19. for (int i = 0 ; i < 3 ; i++) {
  20. for(int j = 0 ; j<3; j++) {
  21. printf("row %d and column %d: ", i+1, j+1);
  22. scanf("%d", &matB[i][j]);
  23. }
  24. }
  25. printf("Select operation to perform on above matrices:\n1. Addition\n2. Subtraction\n3. Multiplication\n4. Transpose of A or B");
  26. int ch;
  27. scanf("%d", &ch);
  28. switch(ch){
  29. case 1: add(matA[3][3], matB[3][3]);
  30. break;
  31. case 2: sub(matA[3][3], matB[3][3]);
  32. break;
  33. case 3: product(matA[3][3], matB[3][3]);
  34. break;
  35. case 4: trans(matA[3][3], matB[3][3]);
  36. break;
  37. default: printf("This is not a valid operation!");
  38. }
  39. return 0;
  40. }
  41. int add(int matrixA, int matrixB){
  42. int sum[3][3];
  43. printf("The sum of matrix A and B is: \n");
  44. for(int i=0; i<3; i++){
  45. for(int j=0; j<3; j++){
  46. sum[i][j] = matrixA[i][j] + matrixB[i][j];
  47. printf("%d ", sum[i][j]);
  48. }
  49. printf("\n");
  50. }
  51. }
  52. int sub(int matrixA, int matrixB){
  53. int sub[3][3];
  54. printf("The diffrence of matrices A and B (A-B) is: \n");
  55. for(int i=0; i<3; i++){
  56. for(int j=0; j<3; j++){
  57. sub[i][j] = matrixA[i][j] - matrixB[i][j];
  58. printf("%d ", sub[i][j]);
  59. }
  60. printf("\n");
  61. }
  62. }
  63. int product(int matrixA, int matrixB){
  64. int multi[3][3];
  65. printf("The product of matrix A and B is: \n");
  66. for(int i=0; i<3; i++){
  67. for(int j=0; j<3; j++){
  68. for(int k=0; k<3; k++){
  69. multi[i][j] = matrixA[i][j] * matrixB[j][k];
  70. printf("%d ", multi[i][j]);
  71. }
  72. }
  73. printf("\n");
  74. }
  75. }
  76. int trans(int matrixA, int matrixB){
  77. printf("Transpose of matrix A: \n");
  78. int temp1 = matrixA;
  79. for(int i=0; i<3; i++){
  80. for(int j=0; j<3; j++){
  81. matrixA[i][j]=temp1[j][i];
  82. printf("%d ", matrixA[i][j]);
  83. }
  84. printf("\n");
  85. }
  86. printf("Transpose of matrix B: \n");
  87. int temp2 = matrixB;
  88. for(int i=0; i<3; i++){
  89. for(int j=0; j<3; j++){
  90. matrixB[i][j]=temp2[j][i];
  91. printf("%d ", matrixB[i][j]);
  92. }
  93. printf("\n");
  94. }
  95. }
Success #stdin #stdout 0.02s 25568KB
stdin
Standard input is empty
stdout
// Online C compiler to run C program online
#include <stdio.h>
int add(int matrixA, int matrixB); 
int sub(int matrixA, int matrixB); 
int product(int matrixA, int matrixB); 
int trans(int matrixA, int matrixB);
int main() {
    int matA [3] [3]; 
    //taking input from user 
    printf("Enter values for a matrix A(3x3) :\n"); 
    for (int i = 0; i < 3 ; i++) { 
        for(int j = 0 ; j < 3 ; j++) { 
            printf("row %d and column %d: ", i + 1 , j+1); 
            scanf("%d", &matA[i][j]); 
        }
    }
    int matB [3] [3]; 
    printf("\nEnter values for matrix B(3x3) :\n"); 
    for (int i = 0 ; i < 3 ; i++) { 
        for(int j = 0 ; j<3; j++) {
            printf("row %d and column %d: ", i+1, j+1); 
            scanf("%d", &matB[i][j]);
        }
    }
    printf("Select operation to perform on above matrices:\n1. Addition\n2. Subtraction\n3. Multiplication\n4. Transpose of A or B");
    int ch;
    scanf("%d", &ch);
    switch(ch){
    case 1: add(matA[3][3], matB[3][3]); 
            break;
    case 2: sub(matA[3][3], matB[3][3]); 
            break;
    case 3: product(matA[3][3], matB[3][3]); 
            break;
    case 4: trans(matA[3][3], matB[3][3]); 
            break;
    default: printf("This is not a valid operation!");
    }
    return 0;
}
int add(int matrixA, int matrixB){
    int sum[3][3];
    printf("The sum of matrix A and B is: \n");
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            sum[i][j] = matrixA[i][j] + matrixB[i][j];
            printf("%d      ", sum[i][j]);
        }
        printf("\n");
    }
}
int sub(int matrixA, int matrixB){
    int sub[3][3];
    printf("The diffrence of matrices A and B (A-B) is: \n");
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            sub[i][j] = matrixA[i][j] - matrixB[i][j];
            printf("%d      ", sub[i][j]);
        }
        printf("\n");
    }
}
int product(int matrixA, int matrixB){
    int multi[3][3];
    printf("The product of matrix A and B is: \n");
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<3; k++){
                multi[i][j] = matrixA[i][j] * matrixB[j][k];
                printf("%d      ", multi[i][j]);
            }
        }
        printf("\n");
   }
}
int trans(int matrixA, int matrixB){
    printf("Transpose of matrix A: \n");
    int temp1 = matrixA;
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            matrixA[i][j]=temp1[j][i];
            printf("%d      ", matrixA[i][j]);
        }
        printf("\n");
    }
    printf("Transpose of matrix B: \n");
    int temp2 = matrixB;
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            matrixB[i][j]=temp2[j][i];
            printf("%d      ", matrixB[i][j]);
        }
        printf("\n");
    }
}