#include<bits/stdc++.h>
using namespace std;
int main() {
srand(time(0)); // 初始化随机种子[[4]]
int n;
cout << "请输入练习次数:";
cin >> n;
while(n--) {
int num1 = rand()%201 - 100; // 生成-100到100的随机数
int num2 = rand()%201 - 100;
char ops[] = {'&', '|', '^'};
char op = ops[rand()%3]; // 随机选择运算符[[5,12]]
cout << num1 << " " << op << " " << num2 << " = ? ";
int answer, correct;
// 计算正确答案[[12]]
if(op == '&') correct = num1 & num2;
else if(op == '|') correct = num1 | num2;
else correct = num1 ^ num2;
cin >> answer;
if(answer == correct) {
cout << "正确" << endl;
} else {
cout << "错误,正确答案是:" << correct << endl;
}
}
return 0;
}
草稿本!!!
于 2024-11-17 11:33:27 首次发布