#XXSY2024HDP. 2024C++算法创意实践初赛华东小学组
2024C++算法创意实践初赛华东小学组
2024C++算法创意实践初赛小学组p
初赛 智能算法应用挑战 小学组(华东)
一、单选题(共15题)
1.有以下函数,当调用语句为long p = fun(3, 3);时,返回的p值 ( )
long fun(int x, int y) {
int i;
long p = 1;
for(i = 0; i < y; i++)
p *= x;
return p;
}
{{ select(1) }}
- 3
- 9
- 27
- 71
2.下列事件中的必然事件是 ( )
{{ select(2) }}
- 小A同学参加下周的数学考试,一定能考100分
- 射击运动员射靶10次,必定能有1次正中靶心
- 打开电视机,正好在播放新闻联播
- 口袋中有2个红球和1个白球,从中摸出2个球,必定至少有1个红球
3.二进制数0.101转换为十进制数为 ( ){{ select(3) }}
- 0.5
- 0.625
- 0.2
- 0.75
4.有A、B、C、D、E五个同学站成一排,如果A和B必须站在一起,则有多少种不同的排法 ( )
{{ select(4) }}
- 24
- 48
- 60
- 120
5.在DevC++中,C++源程序文件的默认扩展名为______,C++目标文件连接而成的可执行文件的默认扩展名为______ ( ){{ select(5) }}
- .c,.exe
- .cpp,.exe
- .exe,.cpp
- .exe,.c
6.有以下函数定义,当n传入数为10时,返回值应为 ( )
int func(int n) {
if(n == 1)
return 1;
else
return func(n-1) + n;
}
{{ select(6) }}
- 45
- 55
- 66
- 1
7.下面哪种循环语句在条件判断之前至少会执行一次循环体 ( )
{{ select(7) }}
- for
- while
- do-while
- switch
8.填写以下程序,使其输出“Hello World!”,横线处应填写 ( )
#include<iostream>
using namespace std;
int main() {
______ << "Hello, world!" << endl;
return 0;
}
{{ select(8) }}
- cin
- cout
- std::cin
- std::cout
9.有两个函数fun1()和fun2()定义如下,在主函数中有:int x = 1; x = fun1(x);调用,此时x的值为( )
int fun1(int x) {
x++;
fun2(x);
return x;
}
void fun2(int x) {
x++;
}
{{ select(9) }}
- 1
- 2
- 3
- 4
10.以下程序段运行后,输出应为 ( )
int a, b;
for(a=1, b=1; a<=100; a++) {
if(b>20)
break;
if(b%4==1) {
b = b+4;
continue;
}
b = b-5;
}
cout << a;
{{ select(10) }}
- 100
- 20
- 9
- 6
11.以下程序段运行后,输入:ABCdef,输出应为( )
char ch;
while((ch = getchar()) != '\n') {
if(ch>='A' && ch<='Z')
ch = ch+32;
else if(ch>='a' && ch<='z')
ch = ch-32;
cout << ch;
}
{{ select(11) }}
- ABCdef
- abcdef
- ABCDEF
- abcDEF
12.下列代码中,哪一个选项正确的输出了num的值 ( )
int main() {
int num = 10;
cout << num++ << endl;
cout << ++num << endl;
cout << num-- << endl;
cout << --num << endl;
return 0;
}
{{ select(12) }}
- 10 12 12 10
- 10 12 11 9
- 11 12 12 10
- 11 12 11 9
13.斐波那契数列的第1和第2个数分别为0和1,从第三个数开始,每个数等于其前两个数之和,即F(0)=0, F(1)=1,F(N)=F(N-1)+F(N-2), 其中N>1。为求斐波那契数列中的前20个数,要求每行输出5个数。编写了以下程序,在3个空格处应填写哪些内容 ( )
#include<iostream>
usingnamespacestd;
int main() {
int n = 20;
int f1 = 0, f2 = 1;
int fn;
cout << "斐波那契数列前" << n << "个数为:" << endl;
for(int i=1; i<=n; i++) {
if(i==1) {
fn = f1;
}
elseif(i==2) {
fn = f2;
}
else {
fn =___①___;
f1 = f2;
f2 =___②___;
}
cout << fn << "\t";
if(___③___) {
cout << endl;
}
}
return0;
}
{{ select(13) }}
- f1,fn,i==5
- "fn,f1+fn,i/5==0'
- f1+f2,fn,i%5==0
- 'f1+f2,f1,i%5 ==0'
14.以下程序输出多组数字,其中包括下列选项中的哪个选项 ( )
#include<iostream>
usingnamespacestd;
int main() {
int g,s,b;
for(int n=100; n<1000; n++) {
b = n/100;
s = n/10%10;
g = n%10;
if(g*g*g + s*s*s + b*b*b == n) {
cout << n << endl;
}
}
return0;
}
{{ select(14) }}
- 407,153
- 408,154
- 408,153
- 407,159
15.下面程序运行后输入4,输出结果应是 ( )
#include <iostream>
usingnamespacestd;
int fac(int n) {
if(n<=1)
return1;
else
return n * fac(n-1);
}
int main() {
int n = 0;
cin >> n;
int ret = fac(n);
cout << ret;
return0;
}
{{ select(15) }}
- 4
- 12
- 24
- 48
二、判断题(共5题)
1.如果定义了一个函数int min(int a, int b);用来返回a和b中较小的数,那么,想求15、26、47三个数中最小的数,用int m = min(15, min(26, 47));这种调用形式 (){{ select(16) }}
- 正确
- 错误
2.continue语句只能出现在循环体中(){{ select(17) }}
- 正确
- 错误
3.在下面程序段中,循环体的循环次数为4次。
int i =0;
do
i++;
while(i*i <10);
{{ select(18) }}
- 正确
- 错误
4.有以下程序段,它的输出结果是10 8 6 4 2 0。
for(int i=10; i>0; i-=2) {
cout << i << " ";
}
{{ select(19) }}
- 正确
- 错误
5.C++函数参数的作用域是函数体内。{{ select(20) }}
- 正确
- 错误