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 许红波239500234.md #63

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
61 changes: 61 additions & 0 deletions homework1/许红波239500234.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
第一题
#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) {
std::cout << "结果: " << num1 + num2 << std::endl;
} else if (choice == 2) {
std::cout << "结果: " << num1 - num2 << std::endl;
} else {
std::cout << "无效的操作选择!" << std::endl;
}
return 0;
}
第二题
#include <iostream>
using namespace std;
int main() {
int number;
cout << "请输入一个整数:";
cin >> number;
if (number % 2 == 0) {
std::cout << number << " 是偶数。" << std::endl;
} else {
std::cout << number << " 是奇数。" << std::endl;
}
return 0;
}
第三题
#include <iostream>
#include <cstdlib>
#include <ctime>
int main() {
std::srand(std::time(0));
int secretNumber = std::rand() % 10 + 1;
int guess;
int attempts = 0;
std::cout << "欢迎来到猜数字游戏!" << std::endl;
std::cout << "我已经想好了一个 1 到 10 之间的数字。" << std::endl;
while (true) {
std::cout << "请输入你的猜测: ";
std::cin >> guess;
attempts++;
if (guess < secretNumber) {
std::cout << "猜小了!" << std::endl;
} else if (guess > secretNumber) {
std::cout << "猜大了!" << std::endl;
} else {
std::cout << "恭喜你,猜对了!" << std::endl;
std::cout << "你一共猜了 " << attempts << " 次。" << std::endl;
break; // 猜对了,退出循环
}
}
return 0;
}