Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create 杨蕊心239500306.md #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions 杨蕊心239500306.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
## 题目1:简单计算器
#include <iostream>
using namespace std;
int main()
{
int num1, num2, choice;
cout << "请输入第一个整数:";
cin >> num1;
cout << "请输入第二个整数:";
cin >> num2;
cout << "请选择操作(1:加法,2:减法):";
cin >> choice;
if (choice == 1)
{
cout<<"结果: "<<num1+num2<<endl;
}
else if (choice == 2)
{
cout<<"结果: "<<num1-num2<<endl;
}
else
{
cout << "无效的选择,请输入1或2。" <<endl;
}

return 0;
}
![830cd3be241d7bae35445895d9b1cad](https://github.com/user-attachments/assets/db57f02e-7e39-4611-99bf-b883b39b7574)




## 题目2:判断奇偶数
#include <iostream>
int main()
{
std::cout << "请输入一个整数: ";
int number;
std::cin >> number;
if (number % 2 == 0)
{
std::cout << number << " 是偶数。" << std::endl;
}
else
{
std::cout << number << " 是奇数。" <<std:: endl;
}

return 0;
}
![1374f133f4abd96f023a159e9f4f85b](https://github.com/user-attachments/assets/6149de5a-b2ad-4d8b-b97d-8d22c32a81ce)


## 题目3:简单的猜数字游戏

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int target, guess, attempts = 0;
srand(time(0));
target = rand() % 10 + 1;
printf("欢迎来到猜数字游戏!\n");
printf("我已经想好了一个 1 到 10 之间的数字,猜猜看是多少:\n");
while (1) {
printf("请输入你的猜测:");
scanf("%d", &guess);
attempts++;

if (guess < target)
{
printf("猜小了!\n");
}
else if (guess > target)
{
printf("猜大了!\n");
} else
{
printf("恭喜你,猜对了!\n");
printf("你一共猜了 %d 次。\n", attempts);
break;
}
}

return 0;
}

![27344fd5afaaf85c943d799b0bf4807](https://github.com/user-attachments/assets/e69a5ad6-0716-4f04-9330-e408011f56d4)