0

Here is my code, could you please help me?

int main(void)
{
    //ask user for the input
   int n;
   do
   {
       n = get_int("Height: ");
   }
    while (n < 1 || n > 8); 
    
   
    for (int i = -1; i < n; i ++)
    {
        for (int k = n - i; k > 0 ; k --)
        {
            printf(" ");
        }
        for (int j = -1; j < i; j ++)
        {
            printf("#");
        }
        printf("\n");
    }
    
}
0

The specifications state that there must be n-1 spaces in the first line and a hash. In your code, it prints an empty line, then a hash on the next line. The solution is simple. Instead of for (int i = -1; i < n; i ++) use for (int i = 0; i < n; i ++). You can confirm this solution by using a trace table also.

Hope this helps. If it does the please check the tickmark.

You must log in to answer this question.

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