A. 2024年信息素养大赛(5)
2024年信息素养大赛(5)
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
一. 单项选择题(共 15 题,每题 5 分,共计 75 分)
1.执行以下程序段,输入 11 ,则输出的值是?( )
int x;
cin >> x;
cout << x + 2;
{{ select(1) }}
- 10
- 11
- x
- 13
2.在 C++ 中,输入指令是?( ) {{ select(2) }}
- cout
- cin
- clog
- int
3.假设有两个城市:城市 A 和城市 B ,每个城市的温度都在 -50 到 50 摄氏度之间,当且仅当只有一个城市的温度低于 0 时,输出 1 ;也就是说,如果城市 A 的温度低于 0 而城市 B 大于等于 0 ,或者如果城市 A 的温度大于等于 0 而 B 小于 0 ,则输出 1 ,否则输出 0 。 补全(1)和(2)处的代码?( )
#include <iostream>
using namespace std;
int main() {
int a,b;
cin >> a >> b;
if(___(1)__){
if(__(2)___) {
cout << 1;
return 0;
}
}
if(a >= 0) {
if(b < 0) {
cout << 1;
return 0;
}
}
cout << 0;
return 0;
}
{{ select(3) }}
- a<0 b >=0
- a>0 b <=0
- a>=0 b>=0
- a<0 b<0
4.在 C++ 中,表示布尔数据类型的关键字是?( ) {{ select(4) }}
- int
- bool
- double
- string
5.完全数是指一个数恰好等于除它本身之外的所有因数之和,例如: 6 的因数有 1、2、3、6 ,除去 6 之外的因数之和为 1+2+3=6 ,所以 6 为完全数。编写程序,按从小到大的顺序寻找 1 到 10000 之间的完全数,输出第 n 个完全数,n 的范围,补全(1)、(2)和(3)处的代码?( )
#include<iostream>
using namespace std;
int main() {
int n, sum = 0, num = 0;
cin >> n;
for(inti = 1; i < 10000; i++) {
int a = i;
sum = 0;
for(int j = 1; j < a; j++){
if(a % j == 0) {
__(1)__
}
}
if(___(2)___){
num++;
}
if(num == n) {
cout << a;
__(3)__
}
}
return 0;
}
{{ select(5) }}
- sum += i ; sum == a ; continue ;
- sum += j ; sum == a ; break ;
- sum += j ; sum != a ; continue ;
- sum += i ; sum == a ; break ;
6.以下可以作为变量名的是?() {{ select(6) }}
- cnt_1
- 1_cnt
- cnt1_#
- @cnt
- C++ 中有很多数据类型,以下可以定义存储浮点型变量的关键字是?( ) {{ select(7) }}
- int
- double
- char
- long long
8.如果我们想在终端输出变量 x 的值,正确的代码是?( ) {{ select(8) }}
- cin >> x ;
- cout << x ;
- cout >> x ;
- cin << x ;
9.执行以下代码段,变量 x 和 y 的值分别是?( )
int x = 7;
int y = x / 2 * 3;
{{ select(9) }}
- x = 7 , y = 10.5
- x = 7 , y = 10
- x = 7, y = 12
- x = 7, y = 9
10.执行以下代码,输出的结果是?( )
int x = 5, y = 3;
cout << (x > y);
{{ select(10) }}
- true
- false
- 1
- 2
11.在 C++ 中,如果用两个 int 类型的变量 length 和 width 分别表示长方形的长和宽,则可以用来计算长方形面积的表达式是?( ) {{ select(11) }}
- length * width
- length + width
- (length + width) * 2
- length * 2 + width * 2
12.数字直角三角形:给出n,输出一个直角边长为 n 的数字直角三角形。所有数字都是 2 位组成的,如果没有 2 位则加上前导 0 。补全(1)和(2)处的代码?( ) 例如: n 为 5 时,数字直角三角形为:
01
0203
040506
07080910
1112131415
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int cnt = 0;
for(int i=1; i<=n; i++) {
for(int j=1;___(1)___;j++){
cnt ++;
if(___(2)___){
cout << 0;
}
cout << cnt;
}
cout << endl;
}
return 0;
}
{{ select(12) }}
- j <= n cnt < 10
- j <= n cnt > 10
- j <=i cnt < 10
- j <=i cnt > 10
13.编写程序,计算区间 100 ~ n 之间的所有整数( ),数字 x () 共出现的次数,补全(1)、(2)和(3)处的代码?( ) 例如: 100 到 109 中,即 100、101、102、103、104、105、106、107、108、109 中数字 1 出现了 11 次。
#include<iostream>
using namespace std;
int main() {
int n, x, cnt = 0;
cin >> n >> x;
for(int i=100; i<=n; i++){
___(1)___
int g, s, b;
g = a % 10;
___(2)___
___(3)___
if(g == x) {
cnt++;
}
if(s == x) {
cnt++;
}
if(b == x) {
cnt++;
}
cout << cnt << endl
return 0;
}
{{ select(13) }}
- int a = i ; s = a / 10 % 10; b = a / 100 ;
- int g = i ; s = g % 10 ; b = g % 100 ;
- int cnt = i ; s = cnt % 10 ; b = cnt/100 ;
- int a = n ; s = a / 10 ; b = a % 100 ;
14.运行下列程序段,输出的结果是?( )
int n = 572765;
cout << n / 10 % 10;
{{ select(14) }}
- 5
- 6
- 4
- 1
15.下列关于 C++ 语言中变量的叙述,不正确的是?( ) {{ select(15) }}
- 变量定义时可以不初始化
- 变量被赋值之后的类型不变
- 变量没有定义也能够使用
- 变量名必须是合法的标识符
二. 判断题(共 5 题,每题 5 分,共计 25 分)
16.在 C++ 中,变量声明后,如果不初始化,其值是确定的。( ) {{ select(16) }}
- √
- ×
17.在 C++ 中,== 是赋值运算符。( ) {{ select(17) }}
- √
- ×
18.在 C++ 中,整型 int 可以用来存储小数。( ) {{ select(18) }}
- √
- ×
19.在 C++ 中,所有变量都必须在使用前声明其数据类型。( ) {{ select(19) }}
- √
- ×
20.在 C++ 中,变量名可以以字母或下划线开头。( ) {{ select(20) }}
- √
- ×