Kodewick
Start learning →
Starter←→0 / 50

Print a pyramid

#030Starterj < 2 * i - 16 min

Print an n-row pyramid of *: row i has n - i spaces first, then 2i - 1 stars, with no space after the stars. For n = 3, the rows are 2 spaces and 1 star, 1 space and 3 stars, 0 spaces and 5 stars. Finish pyramid(n); the program prints one with n = 3 and one with n = 5.

Should show
  *
 ***
*****
    *
   ***
  *****
 *******
*********
main.c
#include <stdio.h>

void pyramid(int n) {
    for (int i = 1; i <= n; i++) {
        // your code here: print the spaces at the start of this row
        // your code here: print the stars of this row
        printf("\n");
    }
}

int main(void) {
    pyramid(3);
    pyramid(5);
    return 0;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.