C语言编程实现:从我设定好的字符串数组中,随机连续输出5个字符串
答案:2 悬赏:70 手机版
解决时间 2021-11-20 20:55
- 提问者网友:轻浮
- 2021-11-20 02:24
C语言编程实现:从我设定好的字符串数组中,随机连续输出5个字符串
最佳答案
- 五星知识达人网友:不如潦草
- 2021-11-20 02:31
是这样的——
//#include "stdafx.h"//vc++6.0加上这一行.
#include "stdio.h"
#include "stdlib.h"
#include "time.h"
int main(void){
char a[][5]={"北京","上海","武汉","天津","合肥","台湾","香港","澳门","贵州","西安"};
int i,j;
srand((unsigned)time(NULL));
for(i=rand()%10,j=i+5;i
",a[i++]));
return 0;
}还是这样的——
追问哪儿有代码??追答//#include "stdafx.h"//vc++6.0加上这一行.
#include "stdio.h"
#include "stdlib.h"
#include "time.h"
int main(void){
char a[][5]={"北京","上海","武汉","天津","合肥","台湾","香港","澳门","贵州","西安"};
int i;
srand((unsigned)time(NULL));
for(i=0;i<5;i++)
printf("%s
",a[rand()%10]);
return 0;
}没明白你的意思……
//#include "stdafx.h"//vc++6.0加上这一行.
#include "stdio.h"
#include "stdlib.h"
#include "time.h"
int main(void){
char a[][5]={"北京","上海","武汉","天津","合肥","台湾","香港","澳门","贵州","西安"};
int i,j;
srand((unsigned)time(NULL));
for(i=rand()%10,j=i+5;i
return 0;
}还是这样的——
追问哪儿有代码??追答//#include "stdafx.h"//vc++6.0加上这一行.
#include "stdio.h"
#include "stdlib.h"
#include "time.h"
int main(void){
char a[][5]={"北京","上海","武汉","天津","合肥","台湾","香港","澳门","贵州","西安"};
int i;
srand((unsigned)time(NULL));
for(i=0;i<5;i++)
printf("%s
",a[rand()%10]);
return 0;
}没明白你的意思……
全部回答
- 1楼网友:往事隔山水
- 2021-11-20 03:05
#include
#include
#include
void main(){
char a[10][10]={"北京","上海","武汉","天津","合肥","台湾","香港","澳门","贵州","西安"};
int b[10]={0};
srand(time(NULL));
for(int i=0;i<5;i++){
int index;
while(b[(index=rand()%10)]==1);
b[index] = 1;
printf("%s ",a[i]);
}
printf(" ");
}
#include
#include
void main(){
char a[10][10]={"北京","上海","武汉","天津","合肥","台湾","香港","澳门","贵州","西安"};
int b[10]={0};
srand(time(NULL));
for(int i=0;i<5;i++){
int index;
while(b[(index=rand()%10)]==1);
b[index] = 1;
printf("%s ",a[i]);
}
printf(" ");
}
纯手打,望采纳!
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯