酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

帮我写一个游戏的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; } [2024-12-05 12:12:33 | AI写代码神器 | 539点数解答]

相关提问