25 October

Yet another shape program

#include <stdio.h>
int main()
{
const int size = 11;
// top row
for(int i = 0; i < size; i++)
{
printf("*");
}
printf("\n");
// middle
int stars = (size-1)/2;
int spaces = 1;
while( stars >= 1 )
{
// print stars
for(int i = 0; i < stars; i++)
{
printf("*");
}
// print spaces
for(int i = 0; i < spaces; i++)
{
printf(" ");
}
// print stars
for(int i = 0; i < stars; i++)
{
printf("*");
}
stars--;
spaces += 2;
printf("\n");
}
// bottom row
for(int i = 0; i < size; i++)
{
printf("*");
}
printf("\n");
return 0;
}

©2011 Christopher League · some rights reserved · CC by-sa