Lesson 6
This commit is contained in:
35
06/Exercise02.c
Normal file
35
06/Exercise02.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int n, astCount, spaceCount, outAstCount, outSpaceCount;
|
||||
scanf("%d", &n);
|
||||
spaceCount = (n-1)/2;
|
||||
if (n > 2 && n % 2 == 1) {
|
||||
for(astCount = 1; astCount <= n; astCount+=2){
|
||||
for (outSpaceCount = 0; outSpaceCount < spaceCount; outSpaceCount++) {
|
||||
printf(" ");
|
||||
}
|
||||
for (outAstCount = 0; outAstCount < astCount; outAstCount++) {
|
||||
printf("*");
|
||||
}
|
||||
printf("\n");
|
||||
spaceCount--;
|
||||
}
|
||||
astCount = n-2;
|
||||
spaceCount = 1;
|
||||
for(; astCount > 0; astCount-=2) {
|
||||
for (outSpaceCount = 0; outSpaceCount < spaceCount; outSpaceCount++) {
|
||||
printf(" ");
|
||||
}
|
||||
for (outAstCount = 0; outAstCount < astCount; outAstCount++) {
|
||||
printf("*");
|
||||
}
|
||||
printf("\n");
|
||||
spaceCount++;
|
||||
}
|
||||
}
|
||||
else{
|
||||
printf("input error");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user