1

Can someone lend me some advice? I'm having trouble with finding the logic between the space and hashes.

int main(void)
{
    int height, row, hash;

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

    for (row = 0; row < height; row ++)
    {
        for(hash = 0; hash < height + 1; hash ++)
        {
            printf("#");
        }
        printf("\n");
    }
}
  • What have you tried? Inside your for loop, can you use the row number to determine how many spaces or hashes to print? – robert_x44 Sep 20 '17 at 1:50
  • Updated what I have so far. – Perry Tran Sep 20 '17 at 3:12
  • 1
    Like @robert_x44 said, the number of hashes depends on row (rather than height). The number of spaces before the hashes might depend on both row and height. – Blauelf Sep 20 '17 at 7:18
  • Hi Perry, the last line of a pyramid will have <i>height</i> Hashes. And the first line need one Hash, only. Therefore, you've to fill up the left side inside of the first line with <i>height-1</i> spaces. The count of space inside of the second line: <i>height-2</i>. etc. etc. – Jens Fischer Dec 21 '17 at 7:20
  • When I was working on this assignment, I used the same method as Perry, that is, use for loop to repeatedly paint "space" & "#". But I wonder if there is a simpler way. – bobby1208 Feb 26 '18 at 10:09
2

I don't want to spoiler your, so I try to give you a hint. If this is not helping you I can get more concrete.

You know that the peak of mario's hill is 1 hash wide, so you want to print 1 hash in the first loop iteration and 2 in the second and so on until you reached the hill height.But before you print the hash you have to print a certain number of whitespaces. This number decreases every iteration.

| improve this answer | |

You must log in to answer this question.

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