#P1346. 【Day2】阅读程序入门(4题)
【Day2】阅读程序入门(4题)
第 1 题
写出以下程序运行后的输出结果(只填数字):
int x = 45, cnt = 0;
while (x) {
x &= x - 1;
cnt++;
}
cout << cnt;
{{ input(1) }}
第 2 题
写出以下程序运行后的输出结果(只填数字):
int x = 40, cnt = 0;
while (x > 0) {
x >>= 1;
cnt++;
}
cout << cnt;
{{ input(2) }}
第 3 题
写出以下程序运行后的输出结果(填 4 位 0/1 串):
int x = 13;
for (int k = 3; k >= 0; k--) {
if (x & (1 << k)) cout << 1;
else cout << 0;
}
{{ input(3) }}
第 4 题
写出以下程序运行后的输出结果(只填数字):
int a[] = {5, 2, 7, 2, 5};
int ans = 0;
for (int i = 0; i < 5; i++)
ans ^= a[i];
cout << ans;
{{ input(4) }}