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 沈政豪+239500225.md #50

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
93 changes: 93 additions & 0 deletions homework1/沈政豪+239500225.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# 第一题
```cpp
#include <iostream>
using namespace std;

int main() {
int num1, num2, choice, result;
cout << "请输入第一个整数:";
cin >> num1;
cout << "请输入第二个整数:";
cin >> num2;

cout << "请选择操作(1:加法,2:减法):";
cin >> choice;
if (choice == 1) {
result = num1 + num2;
cout << "结果:" << num1 << " + " << num2 << " = " << result << endl;
} else if (choice == 2) {
result = num1 - num2;
cout << "结果:" << num1 << " - " << num2 << " = " << result << endl;
}
return 0;
}

```

![屏幕截图 2024-09-28 150522](https://github.com/user-attachments/assets/00cce20f-24b5-4ebf-aebe-ea7dbc8a8700)


# 第二题
```cpp
#include <iostream>
using namespace std;

int main() {
int num;

cout << "请输入一个整数:";
cin >> num;

if (num % 2 == 0) {
cout << num << " 是偶数。" << endl;
} else {
cout << num << " 是奇数。" << endl;
}
return 0;
}

```

![屏幕截图 2024-09-28 150607](https://github.com/user-attachments/assets/64a983cb-4931-480f-95b4-90ba4ad16bdf)



# 第三题
```cpp
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main() {
srand(time(0));
int number = rand() % 10 + 1;
int guess, attempts = 0;
cout << "我想了一个 1 到 10 之间的数字,请猜一猜:" << endl;
do {
cout << "你的猜测:";
cin >> guess;
attempts++;
if (guess > number) {
cout << "猜大了,请再试一次。" << endl;
} else if (guess < number) {
cout << "猜小了,请再试一次。" << endl;
}
} while (guess != number);
cout << "恭喜你,猜对了!你总共猜了 " << attempts << " 次。" << endl;
return 0;
}

```

![屏幕截图 2024-09-28 150645](https://github.com/user-attachments/assets/8d490bb5-725d-4394-b2a7-4f048bb5624c)







warframe很好玩

![屏幕截图(11)](https://github.com/user-attachments/assets/633a2be0-0f53-4fad-b989-c2648bb52e79)