嘿,我想问一下我是否有一个单词列表,比如“老虎、狮子、大象、斑马、马、骆驼、鹿、鳄鱼、兔子、猫”,我可以在 c 编程中随机生成 5 个单词吗?例如:
虎, 斑马, 猫, 鹿, 马
或者
鳄鱼, 兔子, 骆驼, 斑马, 大象
等
提前谢谢你:D
编辑:
#include <stdio.h>
#include <string.h>
#define SIZE 10
int main ()
{
char arr2[SIZE][20] = { "tiger", "lion", "elephant", "zebra", "horse", "camel", "deer", "crocodile", "rabbit", "cat" };
int x = 0;
srand(time(NULL));
while (x < SIZE - 5)
{
arr2 [x][20] = rand ();
printf ("%s\n", arr2[x]);
x++;
}
system ("pause");
return 0;
}