Last active
August 29, 2015 14:07
-
-
Save henrybear327/18dfe764f7e891f711fd to your computer and use it in GitHub Desktop.
CCU programming course bonus question 1 solution 1
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> | |
int main() | |
{ | |
int current_row, total_upper_row, star, space; | |
printf("Please enter a number: "); | |
scanf("%d", &total_upper_row); | |
for(current_row = 1; current_row <= total_upper_row; current_row++) | |
{ | |
for(star = total_upper_row - current_row + 1; star >= 1; star--) | |
//print stars on left-hand side | |
printf("*"); | |
for(space = 1; space <= current_row * 2 + 1; space ++) | |
printf(" "); | |
for(star = total_upper_row - current_row + 1; star >= 1; star--) | |
//print stars on right-hand side | |
printf("*"); | |
printf("\n"); //new line after all stars and spaces are printed | |
} | |
printf("\n"); | |
for(current_row = total_upper_row; current_row >= 1; current_row--) | |
{ | |
for(star = total_upper_row - current_row + 1; star >= 1; star--) | |
//print stars on left-hand side | |
printf("*"); | |
for(space = 1; space <= current_row * 2 + 1; space ++) | |
//print space | |
printf(" "); | |
for(star = total_upper_row - current_row + 1; star >= 1; star--) | |
{ | |
//print stars on right-hand side | |
printf("*"); | |
} | |
printf("\n"); //new line after all stars and spaces are printed | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment