gpt4 book ai didi

c - 如何根据给定的数字制作金字塔?

转载 作者:太空宇宙 更新时间:2023-11-04 06:14:21 25 4
gpt4 key购买 nike

<分区>

我正在尝试用给定数量的星星制作倒金字塔。

当我们知道行数时,任何人都可以画出倒金字塔。

我们可以像这样制作倒金字塔

#include <stdio.h>
int main()
{
int i, space, rows, k=0, count = 0, count1 = 0;

printf("Enter number of rows: ");
scanf("%d",&rows);

for(i=1; i<=rows; ++i)
{
for(space=1; space <= rows-i; ++space)
{
printf(" ");
++count;
}
while(k != 2*i-1)
{
if (count <= rows-1)
{
printf("%d ", i+k);
++count;
}
else
{
++count1;
printf("%d ", (i+k-2*count1));
}
++k;
}
count1 = count = k = 0;

printf("\n");
}
return 0;
}

Result

* * * * * * * * *
* * * * * * *
* * * * *
* * *
*

但就我而言,我想制作一个倒金字塔。问完星星的数量,想做金字塔的形状。我无法决定有多少行可以使它的形状像一个倒金字塔。

(Not Below Exmaple is only for reference it is not compulsory to follow the same pattern , someone said to if you have any number of starts how you will arrange those stars to make it shape like Inverted Pyramid (this may be incomplete) , according to me thought of printing the shape like below but those are not uniform )

**Case** :
1. User Enters : 9

* * * * *
* * *
*

2. User Enters : 8

* * * *
* * *
*




3. User Enters : 7

* * * *
* * *

(No matter if shape completes or not, but it should print like this)

4. User Enters : 6

* * *
* *
*

是否可以根据给定的星数决定行数?

我将利用此逻辑在 ScrollView 中创建动态 View 。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com