例题分析 第四大题:阅读程序题(位运算综合)
第1题
#include<bits/stdc++.h>
using namespace std;
int main(){
int a, b, c, d;
cin >> a >> b >> c;
a=(a&b)>>1;
b=(b|c)>>1;
c=(c^a)>>1;
d = (a +b+c)<<2;
cout <<d << "\n";
return 0;
}
判断题
- 执行语句
a=(a & b)>>1 时,使用的是输入的原始b值。( )
{{ select(1) }}
- 语句
c=(c^a)>>1 中,a的值是初始输入的a值。( )
{{ select(2) }}
- 若输入
a=2,b=2,c=2,则经过计算后a的值为1。( )
{{ select(3) }}
- 对于任意输入的非负整数a、b、c,输出的d一定是4的倍数。( )
{{ select(4) }}
选择题
- 若输入为4 6 2,则程序的输出结果为( )
{{ select(5) }}
- 若输入为3 5 1,则程序的输出结果为( )
{{ select(6) }}
第2题
#include<bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, c, d;
cin >> n;
a = (n % 10) & (0xf);
b = (n / 10 % 10) | (0xf);
c = (n / 100 % 10) ^ (0xf);
d = (a + b + c) << 1;
cout << d << "\n";
return 0;
}
判断题
- 表达式
(n % 10) & (0xf)的结果与n % 10的值相同。( )
{{ select(7) }}
- 对于任意输入的n,变量b的值一定是15。( )
{{ select(8) }}
- 若n是三位数,c的计算使用了n的百位数字。( )
{{ select(9) }}
- 输出d的值一定是偶数。( )
{{ select(10) }}
选择题
- 若输入
n=123,则程序的输出结果为( )
{{ select(11) }}
- 若输入
n=7,则程序的输出结果为( )
{{ select(12) }}