I am really confused with mario half pyramid in pset1. I only need some help just give me a hint if I going right till now and what can I do for the #

   #include <cs50.h>
   #include <stdio.h>

   int main(void)
    int h ;
    h=0 ;
         h = get_int();
     while ( h< 0 || h > 23);
      int i;
       for (i=0;i<h;i++)
          int s;
              printf("  ");


I know that there must be an equation here but I don't really know how to insert it. I tried a lot please give me some hints

1 Answer 1


You could have an if, using some formula with s, i, or h, and some comparison operator like < or <= or the other way around, which decides whether to print a space or a hash.

Or use two inner loops (on the same level, one after the other), first for the spaces, second for the hashes.

Print "\n", or "#\n", or "##\n" (pick the one that's right for your loops) after the inner loop, not within.

  • if I remove the # part above the spaces are working right but the problem is with the # part whenever I tried a lot of times but I didn't reach a solution Commented Jun 20, 2017 at 18:45
  • In above code, you could like if (s + i <= h) { printf(" "); } else { printf("#"); } in the inner loop and printf("##\n"); after it.
    – Blauelf
    Commented Jun 21, 2017 at 6:48

You must log in to answer this question.

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