Matrix Addition in C

Wait What
0






matrix addition11.html






#include<stdio.h>
#include<conio.h>
int main()
{
int i,j;
int m1[2][2],m2[2][2],res[2][2];
// first matrix is being called....
printf("Enter the elements of your first matrix:");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&m1[i][j]);
}

}
// second matrix is being demanding
printf("\nEnter the elements of your second matrix:");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&m2[i][j]);
}

}
// Addition...
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
res[i][j]=m1[i][j]+m2[i][j];
}
}
// printing....
printf(" \nthe addition of these matrices is:\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d ",res[i][j]);
if(j==1)
printf("\n");
}

}
getch();
return 0;
}





Post a Comment

0Comments
Post a Comment (0)
To Top