69,368
社区成员
发帖
与我相关
我的任务
分享
/* 给定10个数(不重复) 从中选取3个 并将所有结果(不含重复的结果)显示
author:tlw112
web:http://topic.csdn.net/u/20090501/21/ad52e29a-ba5e-4c63-89b1-6aa3a2179ea6.html
*/
#include <stdio.h>
#include <time.h>
int main(void)
{
int i,j,k;
int a[10]={1,2,3,4,5,6,7,8,9,10};
int out[2]; /*保存前两个数的记录*/
srand(time(0));
for(i=0;i <3;){
j=rand()%10;
if(0==i){
printf("\t%d",a[j]);
}else if(a[j]!=out[0]&&a[j]!=out[1]){ /*判断是否与前面的数相同*/
printf("\t%d",a[j]);
}else{
continue;
}
k=i;
while(1-k>=0){ /*记录前面出现过的数*/
out[1-k]=a[j];
k++;
}
i++;
}
getchar();
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int i,j;
int a[10]={1,2,3,4,5,6,7,8,9,10};
srand(time(0));
for(i=0;i <3;i++){
j=rand()%10;/*随机产生3个数 0到9*/
printf("%d\t",a[j]);
}
getchar();
}