1 #include<stdio.h>
int main()
{
int sum;
char c;
int n;
scanf("%d %c", &sum, &c);
for (int i = 0; i <= 100; i++)
{
if ((ii) * 2 - 1 == sum)
{
n = i;
break;
}
else if ((ii) * 2 - 1 > sum)
{
n = i - 1;
break;
}
}
int t = n;
int counter = 0;
while (t)
{
for (int i = 1; i <= counter; i++)
{
printf(" ");
}
for (int i = 1; i <= (2 * t - 1); i++)
{
printf("%c", c);
}
printf("
");
counter++;
t--;
}
t = 2;
counter = n - 2;
while (t<=n)
{
for (int i = 1; i <= counter; i++)
{
printf(" ");
}
for (int i = 1; i <= (2 * t - 1); i++)
{
printf("%c", c);
}
printf("
");
counter--;
t++;
}
if (sum == 0)
printf("0
");
else
printf("%d
", sum - (2 * n*n - 1));
system("pause");
return 0;
}
2 运用while语句打印出上半部分的行数,再用两个for语句确定上下两部分的行数,for语句中再镶嵌for语句确定“*”与空格的个数
3 while与for的顺序颠倒部分,然后请教教了同学