help me for looping for

input number = 5
1 5
2 4
3
2 4
1 5

input number = 6
1 5
2 4
34
34
2 4
1 5

input number = 9
1 9
2 8
3 7
4 6
5
4 6
3 7
2 8
1 9

for my assignment :)))
I do not see the principle of forming the sequencies.
For example why do 34 follow 2 4?
It looks like this is the requirement:
input number = 5
1   5
 2 4
  3
 2 4
1   5


input number = 6
1    5
 2  4
  34
  34
 2  4
1    5


input number = 9
1       9
 2     8
  3   7
   4 6
    5
   4 6
  3   7
 2     8
1       9


1
2
3
4
5
6
7
8
9
10
11
12
void test(int n)
{
    std::cout << "input number = " << n << std::endl;
    for (int i=1; i<=n; i++)
    {
        std::string line(n+1, ' ');
        line[i-1] = '0' + i;
        line[n-i] = '0' + n - i + 1;
        std::cout << line << std::endl;
    }
    std::cout << std::endl;
}
Last edited on
Why not as

input number = 6
1
2
3
4
5
6
1    5
 2  4
  33
  33
 2  4
1    5
Good question. My suggested code actually outputs this:
input number = 6
1
2
3
4
5
6
1    6
 2  5
  34
  34
 2  5
1    6
Topic archived. No new replies allowed.