酷代码 AI
菜单
服务商
DeepSeek字节豆包讯飞星火
更多选项

C语言实现超有趣的数字猜谜游戏代码

#include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int guess, randomNumber, attempts = 0; // Generate a random number between 1 and 100 srand(time(0)); randomNumber = rand() % 100 + 1; printf("Welcome to the Number Guessing Game!\n"); printf("I have chosen a number between 1 and 100. Try to guess it.\n"); do { printf("Enter your guess: "); scanf("%d", &guess); attempts++; if (guess > randomNumber) { printf("Too high! Try again.\n"); } else if (guess < randomNumber) { printf("Too low! Try again.\n"); } else { printf("Congratulations! You have guessed the number in %d attempts.\n", attempts); } } while (guess != randomNumber); return 0; } ######[AI写代码神器 | 539点数解答 | 2024-12-05 12:12:33]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]