Skip to content

Instantly share code, notes, and snippets.

@marsgpl
Created October 17, 2024 09:26
Show Gist options
  • Save marsgpl/a42f555323aea20317c28ab0ab0ef656 to your computer and use it in GitHub Desktop.
Save marsgpl/a42f555323aea20317c28ab0ab0ef656 to your computer and use it in GitHub Desktop.
#define STARS "****************************************************"
void print_pyramid(int levels_n) {
int max_w = levels_n + levels_n - 1;
for (int level = 1; level <= levels_n; ++level) {
int stars_n = level + level - 1;
int pad = (max_w - stars_n) / 2;
printf("%*s%.*s%*s\n", pad, "", stars_n, STARS, pad, "");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment