You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.0 KiB
52 lines
1.0 KiB
#include<stdio.h>
|
|
void diamond(int a)
|
|
{
|
|
int b,c,d,t;
|
|
d=0;
|
|
t=a;//将初始数数据给t
|
|
while(a--)//空格数逐层递减
|
|
{
|
|
for(b=0; b<a; b++)
|
|
{
|
|
printf(" ");
|
|
}
|
|
printf("*");
|
|
for(c=1; c<d; c++)//菱形内部空格数
|
|
{
|
|
printf("*");
|
|
}
|
|
if(d!=0)printf("*");
|
|
printf("\n");//一行输出结束
|
|
d=d+2;
|
|
}//菱形的上半部分输出结束
|
|
a=t;
|
|
d=d-2;
|
|
a= a- 1;
|
|
d=0;
|
|
while(a--)//输出菱形的下半部分
|
|
{
|
|
for(c=1; c<(t-a); c++)
|
|
{
|
|
printf(" ");
|
|
|
|
}
|
|
printf("*");
|
|
for(c=0; c<a*2-1; c++)
|
|
{
|
|
printf("*");
|
|
}
|
|
d=d+2;
|
|
if(a!=0)
|
|
printf("*");
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
int main()
|
|
{
|
|
int n;
|
|
scanf("%d",&n);
|
|
diamond(n);
|
|
}
|