小编And*_*uun的帖子

数组只打印零

我创建了一个包含随机数的数组,但是当我打印数组时它们都是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
Run Code Online (Sandbox Code Playgroud)

c arrays random printf format-specifiers

1
推荐指数
1
解决办法
847
查看次数

标签 统计

arrays ×1

c ×1

format-specifiers ×1

printf ×1

random ×1