|
#include <math.h>
#include <stdio.h>
int print_stars(int num);
int print_spaces(int num);
int main()
{
int i, j;
int n, m;
begin:
printf("input:\n");
scanf("%d", &n); //n = 5
if (n < 0 || n % 2 == 0)
{
printf("error, exit\n");
return -1;
}
getchar();
for (i = 1; i <= (n + 1) / 2; i++)
{
print_spaces((n + 1) / 2 - i);
print_stars(i);
}
for (i = (n + 1) / 2 - 1; i >= 1; i--)
{
print_spaces((n + 1) / 2 - i);
print_stars(i);
}
getchar();
goto begin;
}
int print_stars(int num)
{
int i;
for (i=1; i<=num; i++)
{
printf("* ");
}
printf("\n");
}
int print_spaces(int num)
{
int i;
for (i=1; i<=num; i++)
{
printf(" ");
}
} |
|