#include<stdio.h>#include<stdlib.h>#include<time.h>#defineNum10//函数的声明 intbackNumber();intsearch(int n);intdoYouWant();//主函数 intmain(int argc,char*argv[]){int m =0;int k, i;int num[Num];//循环10次 保留每一次的次数do{//接收返回值,并将随机产生的数赋值给n int n =backNumber();//将猜测入放进用户猜测函数中 并将猜测次数返回
num[m ++]=search(n);// 将用户是否继续玩的结果进行返回判断
k =doYouWant();if(k ==2){break;}}while(m <10);int max = num[0];int min = num[0];int j =0;int l =0;//便利数组 找到最大值最小值 并保存输出for(i =0; i < m ; i ++){if(max < num[i]){
j = i;
max = num[i];}if(min > num[i]){
l = i;
min = num[i];}}printf("you best score from %d is %d\n", l, num[l]);printf("you worng score from %d is %d\n", j, num[j]);return0;}//产生随机数intbackNumber(){//产生随机数为1-100;int result =rand()%100+1;//返回随机数return result;}//比对函数 查看用户输入是否正确intsearch(int n){int m, count =0, k;do{//用户输入数字printf("please input number \n");scanf("%d",&m);if(m > n){// 输入结果比猜测数大printf("you guess big \n");}elseif(m < n){// 输入结果比猜测数小printf("you guess small \n");}else{// 输入结果与猜测数相等printf("you guess right \n");break;}
count ++;//控制只能输10次}while(count <10);//返回传入数组中保存起来return count;}//询问用户是否要继续玩intdoYouWant(){int n;printf("Do you want replay \n");printf("yes : 1 \n");printf("no : 2 \n");scanf("%d",&n);//返回判断值nreturn n;}