C Record
C Record
5(c[0][0]) 9(𝑐[0][1])
C =[ ]
8(𝑐[1][0]) 9([1][0])
Program:
#include<stdio.h>
int main()
{
int a[10][10],b[10][10],c[10][10],m,n,p,q,i,j;
printf("enter no.of rows and colms of matrix A:");
scanf("%d,%d",&m,&n);
printf("enter no.of rows and colms of matrix B:");
scanf("%d,%d",&p,&q);
if((m==p)&&(n==q))
{
printf("enter %d elements into A:",m*n);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("enter %d elements into B:",p*q);
for(i=0;i<p;i++)
{
for(j=0;j<q;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("\n");
}
printf("elements of matrix C:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d ",c[i][j]);
}printf("\n");
}
}else
{
printf("matrix addition not possible:");
}return 0;
}
Output:
1) enter no.of rows and colms of matrix A:2,2
enter no.of rows and colms of matrix B:3,3
matrix addition not possible
2) enter no.of rows and colms of matrix A:3,3
enter no.of rows and colms of matrix B:3,3
enter 9 elements into A:
123
456
789
enter 9 elements into B:
123
456
789
elements of matrix C:
246
8 10 12
14 16 18