need help

int num, i;
i = 0;

while (i < 3)
{
num = i+3;
for (int a = 1; a < num; a++)
cout << a * num << " ";
cout << endl;
i++;
}

how come the answer is this?
3 6
4 8 12
5 10 15 20

Which outputs do you expect to be different?
can explain how the code work?

int num, i;
i = 0;

while (i < 3)
{
num = i+3;
for (int a = 1; a < num; a++)
cout << a * num << " ";
cout << endl;
i++;
}

how come the answer is this?
3 6
4 8 12
5 10 15 20

I get the feeling this is your homework.
So here's how it works.

AFALASDARW
SKKAYF
DGGH
WIMSLAGF
XGJ DGGH
HJAFL
SFV AFUJWSKW LZWF JWHWSL

Have fun ;).
Topic archived. No new replies allowed.