#include <stdio.h> #include <time.h> #include <stdlib.h> int main() { int x,num,st,ed; char ch; srand((int)time(NULL)); while(1) { printf("请输入你想要猜的数的范围(用空格隔开):"); scanf("%d %d",&st,&ed); ed=ed-st+1; num=rand()%ed+st; printf("请输入你猜的数字:"); scanf("%d",&x); while(x!=num) { if(x>num) printf("猜大了,继续努力~~\n"); if(x<num) printf("猜小了,继续加油哦!\n"); scanf("%d",&x); } printf("真棒!猜对了!!\n"); printf("继续玩请输入Y,否则请输入N\n"); getchar(); scanf("%c",&ch); if(ch=='Y') continue; else break; } return 0; }
.........
原文地址:http://blog.csdn.net/su20145104009/article/details/45937559