What's the problem with this program?

I have to combine two arrays(v1+v2) and create v3.

#include<stdio.h>
int main()
{
int i, j;
float v1[2][3]={{3,4,5},{5,6,7}};
float v2[2][3]={{3,4,5},{4,7,8}};
float v3[2][3];
printf("elementos das matrizes: \n");
for(i = 0; i < 2; i++)
for(j = 0; j < 3; j++)
{
v1[i][j] + v2[i][j] == v3[i][j];
}
for(i = 0; i<2; i++)
for(j = 0; j<3; j++)
{
printf("%f\n", v3[i][j]);
}
return(0);
}
Not working ¬¬
This line of code
 
v1[i][j] + v2[i][j] == v3[i][j];

compares the element in v3 with the sum of the elements in v1 and v2. What you want is to assign the sum of the elements in v1 and v2 to v3, which would be coded
 
v3[i][j] = v1[i][j] + v2[i][j];


I also think that your double for loops ought to be coded
1
2
3
4
5
6
7
8
for(i = 0; i < 2; i++)
    {
    for(j = 0; j < 3; j++)
        {
        //loop contents;
        //...;
        }
    }

so that if you decide to add something, the loop still works.
Topic archived. No new replies allowed.