Program to Add Two Matrix of Order 2*2 using Multidimensional Array In C
Program to Add Two Matrix of Order 2*2 using Multidimensional Array In C
#include<stdio.h>
int main()
{
float a[2][2], b[2][2],c[2][2];
int i,j;
printf(" enter the elements of first matrix\n");
for(i=0;i<2;i++)
{ for(j=0;j<2;j++)
{
printf("Enter a%d%d",i+1;j+1");
scanf("%f",&a[i][j]);
}
}
printf("Enter the elements of 2nd matrix");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("Enter b%d%d",i+1;j+1);
scanf("%f",&b[i][j]);
}
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
c[i][j]=a[i][j]+b[i][j];
}}
printf(" sum of matrix:");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%f/t",c[i][j]);
if(j==1)
printf("/n");
}}
return 0;
}
Output
Enter a11:2
a12:0.5
a21:-1.1
a22:2
enter element of 2nd matrix
enter b11:0.2
b12:0
b21:0.23
b22:23
sum of matrix
2.2 0.5
-0.9 25.0