猜数游戏C语言版(Windows平台)
#include<cstdio> #include<windows.h> #include<time.h> int main() { srand(time(0)); int x, y, z; x = rand() % 100; y = -1; while (z = 0, z <= 100) { while (true) { printf("\n请输入你猜的数:"); scanf_s("%d", &y); z++; if (x > y) { printf("\n你猜的比答案小:"); } else if (x < y) { printf("\n你猜的比答案大:"); } else { printf("\n恭喜你答对了:"); break; } } printf("%d\n", z); } scanf("%d/n", &x); getchar(); }