1、实验代码:
#include<stdio.h>
int main(void)
{
int n,a,b,d=1,i=1;
char c;
scanf("%d %c",&n,&c);
while(d<=n)
{
d+=2*(2*(i+1)-1);
if(d<=n)
i++;
}
for(a=0;a<i;a++)
{
for(b=0;b<a;b++)
printf(" ");
for(b=0;b<2*(i-a)-1;b++)
{
printf("%c",c);
}
printf("
");
}
for(a=2;a<=i;a++)
{
for(b=0;b<i-a;b++)
printf(" ");
for(b=0;b<2*a-1;b++)
{
printf("%c",c);
}
printf("
");
}
printf("%d",n-(d-2*(2*(i+1)-1)));
}
2、流程图: