#include <stdio.h>
##include <stdlib.h>
#include <stdio.h>
#include <time.h>/*用到了族纯岩time函数,所以要有这个头文件*/
#define MAX 6
int main( void)
{
int number[MAX] = {0}
int i,j
srand((unsigned) time(NULL))/*播种子*/兆御
for(i = 0i <MAXi++)
{
number[i] = rand() % 33/*产生33以内的随机整裤搜数*/
while(number[i]==0)
number[i] = rand() % 33
//printf("%d ", number[i])
}
while(1)
{
for(i=0i<6i++)
for(j=i+1j<6j++)
{ if(number[i]==number[j])
{
number[j]=rand() % 33
i=-1
}
}
if(i==6)
break
}
for(i = 0i <MAXi++)
printf("%d ", number[i])
printf("\n")
return 0
}
#include<stdlib.h>#include<stdio.h>
#include<弯码郑time.h>
const int MAX1=33
const int MAX2=16
void main()
{
int 模扰x[6]={0}
int y=0
int i,j,k,r
k=0
srand(time(0))
while(k<6)
{
r=rand()%MAX1+1
for(i=0i<ki++)
if(x[i]==r)
break
x[k++]=r
}
y=rand()%MAX2+1
for(i=0i<6i++)
printf("%d ",x[i])
printf(" %d"埋颂,y)
}
程序修改过了:#include<stdio.h>
#include<stdlib.h>
#include<time.h>
main()
{int r[6],b,i,j
srand(time(NULL))
r[0]=rand()%33+1
for(i=1i<6i++)
{r[i]=rand()%33+1
for(j=i-1j>=0j--)//有改肢悄键动
if(r[i]==r[j])
{i--
break
}
}
for(i=0i<5i++)//有改动
for(j=i+1j<6j++)
{b=r[i]
if(r[j]<运禅r[i])
{b=r[j]
r[j]=r[i]
r[i]=b
}
}
for(i=0i<6i++)
printf("%d ",r[i])
b=rand()%16+1
printf("+ %d",b)
printf("历巧\n")
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)