题型:单选题
求三色彩球的颜色。有数量无限的红(Red)绿(Green)蓝(Blue)三种彩球排成—行,每组先为5个红色球,随 后3个绿色,最后为2个蓝色。每个球都有编号,从左到右依次为1,2,3……。输入整数代表编号,求该编号球的颜 色。下面是C++代码实现,正确说法是( )。
int N, remainder; cin >> N; remainder = N % 10; // remainder变量保存余数 if((1 <= remainder) && (remainder<= 5)) cout << "Red"; else if ((6 <= remainder) && (remainder <= 8)) cout << "Green"; else if ((remainder == 9) || (remainder == 0)) cout << "Blue";
| A. 将 else if ((remainder == 9) || (remainder == 0)) 修改为 else 效果相同 |
B. 将 ((1 <= remainder) && (remainder<= 5)) 修改为 (remainder <= 5) 效果相同 |
| C. else if ((6 <= remainder) && (remainder <= 8)) 写法错误,应修改为 else if (6 <= remainder <= 8) |
D. 根据题意 remainder = N % 10 应修改为 remainder = N / 10 |
更新时间:2025-06-22 15:22:38
|
【知识点】
CCF—GESP C++二级
抱歉! 您未登录, 不能查看答案和解析点击登录
相似题推荐
单选题
下面代码用来找出输入的N个正整数中最大的一个。如果将代码段用流程图来表示,则 L1 标记的代码行应 该使用的图形是( )。
int N, max=0, val;
cin >> N;
while(N){
cin >> val;
if(val > max) // L1
max = val;
N--;
}
cout << max; | A. 圆形框 |
B. 椭圆形框 |
| C. 平行四边形框 |
D. 菱形框 |
2026-09-29
判断题
下面C++代码段执行后将输出 0-3-6-9- 。 ( )
for (int i = 0; i < 10; i++){
if (i % 3)
continue;
cout << i << "-";
}| A.正确 | B.错误 |
2026-09-29
单选题
下面的 C++ 代码段正常执行后其输出的数字图形是( )。
for (i = 1; i < 5; i++){
for (j = 1; j < i+1; j++)
cout << j;
cout << endl;
} | A. 1 12 123 1234 |
B. 1 22 333 4444 |
| C. 1 21 321 4321 |
D. 4 34 234 1234 |
2026-09-29
单选题
下面 C++ 代码段执行后,其输出是( )。
int i, j, cnt;
cnt = 0;
for (i = 0; i < 5; i++){
i = -i; for (j = i; j < -i; j++) cnt += 1;
i = -i;
}
cout << cnt; | A. 5 |
B. 15 |
| C. 20 |
D. 30 |
2026-09-29
