0

I am new to programming and sincerely appreciate any help. I am having difficulties getting the number of hashes and spaces working correctly. Below is my code. Thanks in advance for support.

int main(void)

{
    int height, i, j ,k;

    // get height from user

    do
    {
    printf("height:   ");
    height = get_int();
    }
    while (height < 0 || height > 23);  

    //print lines
    for (i=1; i <= height; i++)
    {
        //print spaces
        for (j = 0; j < (height - 1);j++)
        {
            printf(" ");
        }

        //print hashes
        for (k = 0; k < 1; k++)
        {
            printf("#");
        }
        printf("\n");
    }
}
0

The general approach is fine but the inside of the loops is not. The first for loop starts with zero, the second loop takes into account that Height decreases as the variable i increases, there is a very simple relationship between Height and i, in the third loop is also related to i, think how many # in Each row, you can make a drawing and you will see these relations easily

1
  • thanks! got it.
    – AnneW38
    Jun 5 '17 at 17:24

You must log in to answer this question.

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