Write C program to add two matrices.


#include<stdio.h>
#include<math.h>
int a[10][10],b[10][10],add[10][10];
int row,col,i,j;
main()
{
int i,j;

printf("\n\t\t MATRIX ADDITION\n");
printf("\n\t\t**************\n");
printf("\n INPUT:");
printf("\n*********\n");
printf("\n Enter the row:");
scanf("%d",&row);
printf("\n Enter the column");
scanf("%d",&col);
printf("\n Enter the value:\n");
for(i=0;i<row;i++)
for(j=0;j<col;j++)
{
scanf("%d",&a[i][j]);
}
for(i=0;i<col;i++)
for(j=0;j<row;j++)
{
scanf("%d",&b[i][j]);
}
for(i=0;i<row;i++)
for(j=0;j<col;j++)
add[i][j]=a[i][j]+b[i][j];
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
printf("%d\t",add[i][j]);
printf("\n");
}
getch();
}

0 comments:

Feel free to contact the admin for any suggestions and help.