nested loop

I need to create a nested loop that does the flowing:
The outer loop will count from 1 to 5. The inner loop will count from 1 to 6 and write the product of the outer loop counter multiplied by the inner loop counter, all on the same line with one tab (‘\t’) between. Between the loop ends put a line feed (endl or \n). The result should look like this:
1 2 3 4 5 6
2 4 6 8 10 12
3 6 9 12 15 18 etc,

I have looked in the forums but did not see anything like this. If anyone can help me I would appreciate it. Thank you for your time.
Randy

Below is the code I tried but does not work.

1
2
3
4
5
6
7
8
9
10
  for(cnt1 = 1; cnt1 <= 5; cnt1++)
	{
		for (cnt2 = 1; cnt2 <=6; cnt2++)
		{
			cout <<cnt1 << cnt2 << '\t';
			cout << cnt1 * cnt2;

		}cout << endl;

	}cout << endl;
Why do you output cnt1 and cnt2 individually if you are only supposed to display their product? Other than that, the code is mostly correct.
Last edited on
Thanks L B for your help and quick response. When I read your post it hit me what I did wrong.


Thanks again.
Randy
Topic archived. No new replies allowed.