.net输出一个空心菱形
时间: 2023-05-18 07:02:55 浏览: 91
您可以使用以下代码来输出一个空心菱形:
```
int n, c, k, space = 1;
printf("Enter number of rows:\n");
scanf("%d",&n);
space = n - 1;
for (k = 1; k <= n; k++)
{
for (c = 1; c <= space; c++)
printf(" ");
space--;
for (c = 1; c <= 2*k-1; c++)
{
if (c == 1 || c == 2*k-1)
printf("*");
else
printf(" ");
}
printf("\n");
}
space = 1;
for (k = 1; k <= n - 1; k++)
{
for (c = 1; c <= space; c++)
printf(" ");
space++;
for (c = 1 ; c <= 2*(n-k)-1; c++)
{
if (c == 1 || c == 2*(n-k)-1)
printf("*");
else
printf(" ");
}
printf("\n");
}
```
这段代码将输出一个空心菱形,其中用户需要输入菱形的行数。
阅读全文