未设随机数种子,完整的随机数产生请参考
srand()
还有那输一个比一个,等段时间再比,好像需要某某函数,不太清楚,
高手请留下脚印
#include<stdlib.h>
#include<stdio.h>
int f(int x, int y)
{if(x==y) return 0;
else if(x==y+1||x+2==y||x==y+2) return 1;
else return -1;
}
void main()
{
int i,j,a[5],m,sum=0,b[5];
printf("please put in 1,2or3:\n");
for(i=0;i<5;i++)
scanf("%d",&b[i]) ;
for(i=0;i<5;i++)
{
j=1+(int)(3.0*rand()/(RAND_MAX+1.0));
printf("%d ",j);
a[i]=j;
sum=sum+f(b[i],a[i]);
}
if(sum>0)
printf("congratulation");
else
if(sum<0)
printf("sorry,do you want to try again");
else printf(".....");
}