C语言编程实现:从我设定好的字符串数组中,随机连续输出5个字符串
从字符串数组中{“北京”,“上海”,“武汉”,“天津”,“合肥”,“台湾”,“香港”,“澳门”,“贵州”,“西安”},随机的连续生成5个字符串,用C语言如何编程实现...
从字符串数组中{“北京”,“上海”,“武汉”,“天津”,“合肥”,“台湾”,“香港”,“澳门”,“贵州”,“西安”},随机的连续生成5个字符串,用C语言如何编程实现
展开
2个回答
展开全部
是这样的——
//#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<j;printf("%s\n",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\n",a[rand()%10]);
return 0;
}
没明白你的意思……
展开全部
#include<stdio.h>
#include<stdlib.h>
#include <time.h>
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("\n");
}
纯手打,望采纳!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询