在 C 语言中,可以使用 rand() 函数生成随机数。可以在数组初始化时使用循环将随机数赋值给数组中的每个元素。例如:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
int i;
int arr[5];
srand(time(0));
for (i = 0; i < 5; i++) {
arr[i] = rand();
}
for (i = 0; i < 5; i++) {
printf("%d ", ar