1
int nh, ns, h; // nh - number of hashes, ns - number of spaces, h - height


for (h = 1; h <= n; h++)
{
    for (ns = 23; ns < 23-h; ns--)
        {
        printf(" ");
        }

    for (nh = 2; nh <= n+1; nh++)
        {    
        printf("#"); // for (height == 0, h = n + 1 hash spaces 23 - h
        }
    printf("\n");

    ns--;
    nh++;
}

}

What I am getting is equal number of hashes in every row (spaces are not printing). Why is this wrong? Please help

1

for(initialization;condition;counter)

You are not printing any spaces out because the initialization variable ns = 23, will always be greater than your condition (ns < 23 - h). See the problem? So say if your height is 1, then 23<22. This is not true and so every time your program executes, that for loop does not work and so spaces are not being printed out. And by the way, what is the value of n since it was not specified in your code?

0
for (ns = 23; ns < 23-h; ns--)
    {
    printf(" ");
    }

This loop won't work because ns will always be under 23-h, and also the # of spaces won't start at 23 every single time.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .