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

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. :)

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

In the line 1 declare x as int instead of char. It would be better that way.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.