Here's a good one that handles any size without a lot of complicated looping. :-)
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
int i;
int spaces;
int height;
char *stars;
printf("Enter the height: ");
if (scanf("%d", &height) != 1)
{
return 1;
}
if ((stars = malloc(height*2 + 1)) == 0)
{
return 1;
}
memset(stars, '*', height*2);
stars[height*2] = '\0';
for (spaces = height, i = 1; spaces > 0; i += 2)
{
printf("%*c%.*s\n", spaces--, ' ', i, stars);
}
free(stars);
return 0;
}