Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

c program for the addition of two matrices

0 votes
asked Oct 11, 2019 by anonymous

2 Answers

0 votes
answered Oct 11, 2019 by Bala Avinash (140 points)
#include<stdio.h>
int main()
{
int m,n,i,j,a[10][10],b[10][10],c[10][10];
printf("enter m,n\n");
scanf("%d%d",&m,&n);
printf("enter 1st matrice elements\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("enter 2nd matrice elements\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
printf("sum of 2 matrices\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%3d",c[i][j]);
}
printf("\n");
}
return 0;
}
0 votes
answered Oct 11, 2019 by Harsha (380 points)
edited Oct 15, 2019 by Harsha
#include<stdio.h>
int main()
{
int r1,r2,c1,c2,a[100][100],b[100][100],c[100][100];
printf("entre no.of rows and coloums in matrix 1");
scanf("%d %d",&r1,&c1);
printf("entre no.of rows and coloums in matrix 2");
scanf("%d %d",&r2,&c2);
if(r1==r2 && c1==c2)
{
printf("entre the elements in 1");
int i,j;
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("entre the elements in 2");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf("%d",c[i][j]);
}
printf("\n");
}
}
}
commented Oct 11, 2019 by Harsha (380 points)
if you have doubts text a message to me  insta id "gutsboy_harsha "
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...