C Programming

Sum of two Matrices

Sum of two Matrices is one of the operations performed on Matrices wherein Matrix A and Matrix B are are summed together resulting in a Matrix C which is the new Matrix formed by addition of A & B.

Language :C

[sourcecode language='c']
#include
void main()
{
int a[3][3], b[3][3], c[3][3],sum,i,j;
sum=0;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“Enter the values FOR %d row & %d column: “, i+1,j+1);
scanf(“%d”, &a[i][j]);
}
}
printf(“\n\n Matrix A\n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“\t %d”, a[i][j]);
}
printf(“\n”);
}

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“Enter the values FOR %d row & %d column: “, i+1,j+1);
scanf(“%d”, &b[i][j]);
}
}

printf(“\n\n Matrix B\n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“\t %d”, b[i][j]);
}
printf(“\n”);
}

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}

printf(“\n\n Sum of Matrix\n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“\t %d”, c[i][j]);
}
printf(“\n”);
}
}
[/sourcecode]



{ 4 comments… read them below or add one }

1 Felipe October 23, 2009 at 8:22 pm

DevC say that problem is in &amp

Reply

2 Programming Kid October 27, 2009 at 3:38 am

@Felipe
Please note that the above Source Code has been updated, and will work. Thanks

Reply

3 Felipe October 23, 2009 at 10:22 pm

DevC say that problem is in &amp

Reply

4 Programming Kid October 27, 2009 at 5:38 am

@Felipe
Please note that the above Source Code has been updated, and will work. Thanks

Reply

Leave a Comment

Notify me of followup comments via e-mail. You can also subscribe without commenting.


WordPress - Vaibhav Kanwal