/* Author Mr.Long
* Date 2015年12月2日17:37:47
*/
#include<stdio.h>
#include<iostream>
/* 二分法 */
int main(){
int price,newprice = 0,count = 0;
printf("****猜价格游戏****\n");
printf("设置商品价格(0 - 999):");
input:
scanf("%d",&price);
if(price <=0 || price >= 999){
printf("请输入0 - 999 范围内的价格:");
goto input;
}
system("cls");
while(newprice != price){
printf("请输入你猜的价格:");
scanf("%d",&newprice);
if(newprice > price){
printf("->高了\n");
}else if(newprice < price){
printf("->低了\n");
}else if(newprice == price){
printf("恭喜你,猜对了\n");
break;
}
count++;
}
printf("所用步数:%d",count);
return 0;
}
C语言 二分法 猜价格游戏
最新推荐文章于 2023-02-02 22:58:25 发布