0
void printer(char x)
{
    int d, b, z;

    for(z=x; z>=1; z--) {
        for(b=z; b<=x-1; b++)
            printf(" ");
        for(d=z; d>=1; d--)
            printf("%d ", d);
        printf("\n");
    }
}

that's my code which is supposed to print
4 3 2 1
4 3 2
4 3
4
when input is 4. however, it prints as
4 3 2 1
3 2 1
2 1
1

Edited by Narue: formatted code and fixed code tags

4
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by Arbus
2

Change this

for(d=z; d>=1; d--)

to this

for(d=x; d>x-z; d--)

Now tell me why that works and what you were doing wrong. :)

Edited by Narue: n/a

0

You could use up counting for to increment the stop condition of inner loop and manage with two nested fors.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.