Skip to content

Instantly share code, notes, and snippets.

@henrybear327
Last active August 29, 2015 14:07
Show Gist options
  • Save henrybear327/18dfe764f7e891f711fd to your computer and use it in GitHub Desktop.
Save henrybear327/18dfe764f7e891f711fd to your computer and use it in GitHub Desktop.
CCU programming course bonus question 1 solution 1
#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