Friday, 24 October 2014

Addition of Two Matrixes ( C Program )

Non-Recursive C Program:

Aim: Two print matrix addition.

Program:
#include <stdio.h>
#include <conio.h>
void main()
  { 
   int A[10][10], B[10][10],      sumat[10][10], i, j, R1,C1,R2,C2;
clrscr();
printf("Enter the order of the matrice A \n");
scanf("%d %d", &R1, &C1);
printf("Enter the order of the matrice B \n");
scanf("%d %d", &R2, &C2);
if(R1==R2&&C1==C2)
{
printf("Enter the elements of  matrix A\n");
for(i=0; i<R1; i++)
   {   for(j=0; j<C1; j++)
       {
          scanf("%d",&A[i][j]);
       }
   }

printf("MATRIX A is\n");
   for(i=0; i<R1; i++)
     { for(j=0; j<C1; j++)
          {
              printf("%3d",A[i][j]);
           }
        printf("\n");
     }

printf("Enter the elements of matrix B\n");
   for(i=0; i<R2; i++)
     {
        for(j=0; j<C2; j++)
         {
             scanf("%d",&B[i][j]);
          }
     }

  printf("MATRIX B is\n");
    for(i=0; i<R2; i++)
      {
        for(j=0; j<C2; j++)
          {
             printf("%3d",B[i][j]);
          }
          printf("\n");
      }

for(i=0; i<R1; i++)
{
   for(j=0; j<C1; j++)
         {
           sumat[i][j] = A[i][j] + B[i][j];
          }
  }

printf("Sum matrix is\n");
   for(i=0; i<R1; i++)
      {
        for(j=0; j<C1; j++)
           {
              printf("%3d",sumat[i][j]) ;
            }
      printf("\n");
      }
}
else
  {
  printf("\nMatrice Addition is not possible");
   }
}

Click here to view matrix related programs.

No comments:

Post a Comment