代码如下
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//这是一个对称图形,每个点都有对应的坐标,
//从第一行到中心行,*个数与行数关系是2n-1,空格个数是列数-3
int print_graph(int line, int col)
{
int count;
for (count = 0; count < col - line; count++)
{
printf(" ");
}
for (count = 0; count < 2 * line - 1; count++)
{
printf("*");
}
return 0;
}
int main()
{
int line;
int col = 7;
for (line = 1;line <8;line++)
{
print_graph(line,col);
printf("\n");
}
//从最后一行开始,最后一行的*个数与第一行相对应,空格个数也与第一行对应,
//用对称中心的性质,用对称中心的两倍减去最后一行就是就是第一行,其他行当然也适用次定理
for (line; line<14;line++)
{
print_graph(14-line, col);
printf("\n");
}
system("color 0B");
system("pause");
return 0;
}