C program to perform addition of two matrices
/*******************************************
C program to perform addition of two matrices
**************************************************/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20][20],b[20][20],c[20][20];
int i, j,n,m;
printf("How many rows and columns\n");
scanf("%d%d",&n,&m);
printf("Enter array elements for first array\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter array elements for second array\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("\n");
printf("Following is %d X %d first array\n",n,m);
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
printf("Following is %d X %d second array\n",n,m);
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
printf("Addition of two matrices is\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
c[i][j]=a[i][j]+b[i][j];
printf("%d\t",c[i][j]);
}
printf("\n");
}
printf("End of program");
getch();
}
How many rows and columns
3
3
Enter array elements for first array
1
2
3
4
5
6
7
8
9
Enter array elements for second array
3
4
5
6
7
8
9
1
2
Following is 3 X 3 first array
1 2 3
4 5 6
7 8 9
Following is 3 X 3 second array
3 4 5
6 7 8
9 1 2
Addition of two matrices is
4 6 8
10 12 14
16 9 11
End of program
0 टिप्पण्या
कृपया तुमच्या प्रियजनांना लेख शेअर करा आणि तुमचा अभिप्राय जरूर नोंदवा. 🙏 🙏