C语言猜数字小游戏

来源:互联网 发布:南方全站仪pts数据 编辑:程序博客网 时间:2024/04/30 09:35
#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;elsebreak;}return 0;}

.........



3 0
原创粉丝点击