急求!一道C语言编程题.感谢你的帮助!!

2024-11-01 19:36:11
推荐回答(2个)
回答1:

void fun(int start, int end){
int tmp = start+end;
string str;
cout << tmp/2;
cin >> str;
if (str == "correct"){ cout << "end of program\n";}
else{
if (str == "less"){ fun(tmp/2, end); }
else{ //bigger
fun(start, tmp/2);
}
}
}

回答2:

#include
#include

void guess(int low, int high);

int main(){
Guess(1,1);
return 0;
}

void guess(int low, int high){
char str[5];
printf("%d right?\n",(low+high)/2);
scanf("高?低? %s",str);
if (!strcmp(str,"高"))
guess(low,(low+high)/2);
else if(!strcmp(str,"对")){
getc();
return;
}

else guess((low+high)/2,high);
}