C Program to add two matrices

/* Program to add two matrices */

#include 

int main() {
    int a[3][3];
    int b[3][3];
    int c[3][3];
    int i, j;

    printf("Enter the First matrix:\n");
    for(i=0; i<3; i++)
        for(j=0; j<3; j++)
            scanf("%d", &a[i][j]);

    printf("\nEnter the Second matrix:\n");
    for(i=0; i<3; i++)
        for(j=0; j<3; j++)
            scanf("%d", &b[i][j]);

    printf("\nThe First matrix is");
    for(i=0; i<3; i++) {
        printf("\n");
        for(j=0; j<3; j++)
            printf("%3d", a[i][j]);
    }

    printf("\nThe Second matrix is");
    for(i=0; i<3; i++) {
        printf("\n");
      for(j=0; j<3; j++)
      printf("%3d", b[i][j]);
   }

   /* Add the matrices */
   for(i=0; i<3; i++)
       for(j=0; j<3; j++)
            c[i][j] = a[i][j] + b[i][j];

   printf("\nThe Addition of two matrix is");
   for(i=0; i<3; i++){
       printf("\n");
       for(j=0; j<3; j++)
            printf("%3d", c[i][j]);
   }

   getch();
   return 0;
}

 
Advertisements