Multiply the elements of two arrays

Hi all,

I am trying to multiply two array values for 10 different values, but only the first one is nonzero, others are all 0.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
int numS =10;
int x[15] = {3,4,6,7,8,9,7,6,4,3,2,1,1,4,5};
int C[10][15]= {
    {10,14,15,11,1,0,89,0,909,0,0,1,1,0,0},
    {17,1,17,16,15,31,0,0,42,420,0,142,1,0,0},
    {1,0,0,1,15,0,0,53,1,321,1,135,1,0,0},
    ...
    };

void Function(int numS)
{
    int i,j;
    for(i = 0; i < numS; i++)
    {
        for(j = 0; j < 15; j++)
        {
            result[i] += double(C[i][j]*x[j]);
        }
     
        for(i = 0; i < numS; i++)
        {
            cout <<result[i]<<endl;
        }
    }

}

What is wrong in this code? Thanks
1
2
3
4
5
6
7
8
9
10
11
12
    int i,j;
    for(i = 0; i < numS; i++)
    {
        //...
     
        for(i = 0; i < numS; i++) //When this loop ends, i=numS
        {
            cout <<result[i]<<endl;
        }
        //here i=numS
        //so the outer loop ends
    }
So, the updated code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
int numS =10;
int x[15] = {3,4,6,7,8,9,7,6,4,3,2,1,1,4,5};
int C[10][15]= {
    {10,14,15,11,1,0,89,0,909,0,0,1,1,0,0},
    {17,1,17,16,15,31,0,0,42,420,0,142,1,0,0},
    {1,0,0,1,15,0,0,53,1,321,1,135,1,0,0},
    ...
    };

void Function(int numS)
{
    int i,j;
    for(i = 0; i < numS; i++)
    {
        for(j = 0; j < 15; j++)
        {
            result[i] += double(C[i][j]*x[j]);
        }
     
        for(i = 0; i < numS; i++)
        {
            cout <<result[i]<<endl;
        }
        i = numS;
    }

}


It still gives the same result. Did I misunderstand it?
Topic archived. No new replies allowed.