Trouble with Matrix

I need make a code with this output with the cicle for .

1 2 4 8 16
2 4 8 16 32
3 6 12 24 48
4 8 16 32 64
I have this code but is worng can you help me .
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
28
29
#include <iostream>
#include <time.h>
#include <stdlib.h>
using namespace std;
int main ()
{

int matrix[4][5];
int opc2=0;
for(int f =0; f<4;f++ )
{

cout<<"\n\n";



for(int c = 0;c<5;c++)
{

opc2=matrix[f][c]=(f*2)*(c*2);

cout<<opc2;


cout<<"\t\t";
}

}
}

http://imgur.com/VTCeEAyl.png
Last edited on
What "is worng"? What happens? Code does not compile? Program crashes? Unexpected output?
(We can actually guess some of those answers, but it is better for you if you do explain it.)


PS. Please use code tags. See http://www.cplusplus.com/articles/jEywvCM9/
You can edit your post.
Unexpected output, I presume.

Math trivia:
(f*2)*(c*2) == f*2*c*2 == f*c*2*2 == f*c*4

Lets look at the first value, matrix[0][0]. The f==0 and c==0, therefore 0*0*4 -> 0.
Same goes for the entire row, for f==0 for all of them and on the first colum the c==0 makes 0.

Lets look at the expected output:
1 2  4  8 16
2 4  8 16 32
3 6 12 24 48
4 8 16 32 64

I'll do some magic to it:
1*1 1*2 2*2  4*2  8*2
2*1 2*2 4*2  8*2 16*2
3*1 3*2 6*2 12*2 24*2
4*1 4*2 8*2 16*2 32*2

Put other way:
1*1 1*2 1*4  1*8 1*16
2*1 2*2 2*4  2*8 2*16
3*1 3*2 3*4  3*8 3*16
4*1 4*2 4*4  4*8 4*16

Do you notice any trend that you could express in code?
Topic archived. No new replies allowed.