gpt4 book ai didi

c - 数组只打印零

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

我用随机数创建了一个数组,但是当我打印数组时它们都是 0,这里有什么问题吗?我知道随机数在那里,但仍然是零?

int superArray[SIZE];
int index, counter;

srand( time(0) );

for (index = 0; index < SIZE; index++) //random numbers

superArray[index] = rand() % 21 +1;

for (index = 0; index < SIZE; index++) //vertical print
{
printf("%8.f\n", superArray[index]);
}
printf("%8d\n\n", superArray[8]); //verify that array has random numbers

最佳答案

使用 %d 打印 int 它将起作用:

printf("%d\n", superArray[index]);

关于c - 数组只打印零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30412711/

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