Get Update on recent Technology & Programming

Friday, 10 November 2017

C Program to Addition of two matrices

Posted by   on Pinterest

C Program to Addition of two matrices



#define ROW 3

#define COL 4

#include<stdio.h>

int main(void)

{

 int i,j,mat1[ROW][COL],mat2[ROW][COL],mat3[ROW][COL];

 printf("Enter matrix mat1(%dx%d)row-wise :\n",ROW,COL);

 for(i=0; i<ROW; i++)

  for(j=0; j<COL; j++)

   scanf("%d",&mat1[i][j]);

 printf("Enter matrix mat2(%dx%d)row-wise :\n",ROW,COL);

 for(i=0; i<ROW; i++)

  for(j=0; j<COL; j++)

   scanf("%d",&mat2[i][j] );

 /*Addition*/

 for(i=0; i<ROW; i++)

  for(j=0; j<COL; j++)

   mat3[i][j] = mat1[i][j] + mat2[i][j];

 printf("The resultant matrix mat3 is :\n");

 for(i=0; i<ROW; i++)

 {

  for(j=0; j<COL; j++)

   printf("%5d",mat3[i][j]);

  printf("\n");

 }

 return 0;

}




No comments:
Write comments

Hey, we've just launched a new custom color Blogger template. You'll like it -
Join Our Newsletter