BUPT-homework/semester1/pset3/1-rhombus.c

32 lines
576 B
C

#include <stdio.h>
int main(void) {
// Initialize variables
int level;
scanf("%d", &level);
// Iterate over lines and print rhombus
// Upper half
for (int i = 1; i <= level; i++) {
for (int k = 0; k < level - i; k++) {
printf(" ");
}
for (int j = 0; j < i * 2 - 1; j++) {
printf("*");
}
printf("\n");
}
// Lower half
for (int i = level - 1; i > 0; i--) {
for (int k = 0; k < level - i; k++) {
printf(" ");
}
for (int j = 0; j < i * 2 - 1; j++) {
printf("*");
}
printf("\n");
}
return 0;
}