我的代码在生成 6 个随机人类字符和 6 个随机数时遇到了一些问题,这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
char name[5] = {'Daniel','Bill','Ben','Steve','Drew'};
char animals[5] = {'Dog','Cat','Mouse','Chicken','Bird'};
int age[5] = {25,17,18,50,10};
char city[5] = {'Palo Alto','Escondido','Chicago','Mumbai','Zapopan'};
int main() {
srand(time(NULL));
int a = rand(),b = rand(),c = rand(),d = rand(),e = rand(),f = rand();
printf("Name: %c\nAnimal: %c\nAge: %d\nCity: %c",name[a],animals[a],age[a],city[a]);
printf("Name: %c\nAnimal: %c\nAge: %d\nCity: %c",name[b],animals[b],age[b],city[b]);
printf("Name: %c\nAnimal: %c\nAge: %d\nCity: %c",name[c],animals[c],age[c],city[c]);
printf("Name: %c\nAnimal: %c\nAge: %d\nCity: %c",name[d],animals[d],age[d],city[d]);
printf("Name: %c\nAnimal: %c\nAge: %d\nCity: %c",name[e],animals[e],age[e],city[e]);
printf("Name: %c\nAnimal: %c\nAge: %d\nCity: %c",name[f],animals[f],age[f],city[f]);
return 0;
}
它似乎不起作用 S:我是一个初学者,有人可以帮助我吗?
谢谢!