Formatting output

Hey, I want to output numbers llike this:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 etc

I write such code:

1
2
3
4
5
6
7
8
9
10
  int i=0;
	int j = 0;

	for (i = 1; i <= n; i++) {
		for (j = 1; j <= i; j++)
		{
			cout << j;
		}
		cout << endl;
	}


But it outputs like this:
1
1 2
1 2 3
1 2 3 4

How to output the way I want?
Thanks
Last edited on
What if you had another variable in there, like int n = 1; that you printed inside your loops? (Declare it before the loops, just like i and j.)

Hope this helps.
Last edited on
Looks to me like you are on the right track. You could:
On line 3 create another int e.g. int number = 1;
On line 7, instead of outputting j, output number
After line 9, increment number (i.e. number++;)

Edit: D'oh, too slow.
Last edited on
It happens to me all the time.

By the way, my post count is now a prime number. (But the next time you read this the likelihood that it is still prime is around 12%.)
Yeah, it works.
Thanks guys :)
Topic archived. No new replies allowed.