题目:输入对角线长度,打印对应的菱形(对角线必须是奇数,否则打印出的不是菱形)
代码如下:
#include <stdio.h>
int main()
{
int n,a;
scanf("%d", &n);
a = n / 2;
int q = a;
int f = 1;
for (int i = 0; i <= a; i++)
{
for (int j = 0; j < q; j++)
{
printf(" ");
}
for(int k=0;k<f;k++)
{
printf("*");
}
printf("\n");
q--;
f = f + 2;
} q = n-2; f = 1;
for (int i = 0; i < a; i++)
{
for (int j = 0; j < f; j++)
{
printf(" ");
}
for (int k = 0; k < q; k++)
{
printf("*");
}
printf("\n");
f++;
q=q-2;
}
return 0;
}