Last active
June 6, 2022 07:16
-
-
Save theabbie/1c4b580f5b1fb0130f669c9dbe6c0488 to your computer and use it in GitHub Desktop.
Print Hollow Pyramid in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void main() | |
{ | |
int n = 10; | |
int hollow = 1; | |
int isSpace; | |
printf("Edge length? "); | |
scanf("%d", &n); | |
printf("Is Hollow?\n 0. No\n 1. Yes\n"); | |
scanf("%d", &hollow); | |
for (int i = 1; i <= n; i++) | |
{ | |
isSpace = i != n && hollow; | |
for (int j = 1; j <= n - i; j++) | |
printf(" "); | |
if (i > 1) | |
printf("*"); | |
for (int j = 1; j < 2 * i - 2; j++) | |
{ | |
if (isSpace || j & 1) | |
printf(" "); | |
else | |
printf("*"); | |
} | |
printf("*\n"); | |
} | |
} | |
// Edge length? 8 | |
// Is Hollow? | |
// 0. No | |
// 1. Yes | |
// 1 | |
// * | |
// * * | |
// * * | |
// * * | |
// * * | |
// * * | |
// * * | |
// * * * * * * * * |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment