"G. B" <
g...@gb.com> writes:
> This is the starting code:
Questions like this are best not cross-posted. The solutions might
become radically different in C and in C++. I've set followup-to
comp.lang.c as my answer is in C.
> for (int i = 0; i < 10; i++)
> {
> for (int j = 1; j < 7; j++)
> {
> // Console.Write("{0} ", j);
> printf("%d",j);
> }
> // Console.WriteLine();
> cout << "\n";
> }
>
> This code will produce:
>
> 1 2 3 4 5 6
No, there is no space in the printf so you don't get any in the output!
> 1 2 3 4 5 6
> 1 2 3 4 5 6
> 1 2 3 4 5 6
> 1 2 3 4 5 6
> 1 2 3 4 5 6
> 1 2 3 4 5 6
> 1 2 3 4 5 6
> 1 2 3 4 5 6
> 1 2 3 4 5 6
>
> How do I change it {neatly} so that it produces:
>
> 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 30
> 31 32 33 34 35 36
> 37 38 39 40 41 42
> 43 44 45 46 47 48
> 49 50 51 52 53 54
> 55 56 57 58 59 60
I'm guessing you don't want the crazy spacing. I'd just have one loop
to numbers from 1 to 60 and a newline when the counter is = 0 mod 6:
for (int i = 1; i <= 60; i++)
printf("%-6d", i, i % 6 ? "" : "\n");
(I've guessed how you want the single-digit numbers aligned.)
--
Ben.