信息素养大赛模拟题一

选择题


1、

C++ 中,可以计算两个数相除的余数的运算符是( )

          

          

          

          
2、 (1) 假设有两个城市:城市 A 和城市 B。每个城市的温度都在 −50 到 50 摄氏度之间。当且仅当只有一个城市的温度低于 0 时,输出 1,也就是说,如果城市 A 的温度低于 0 而城市 B大于等于 0;或者如果城市 A 的温度大于等于 0 而 B 小于 0,则输出 1,否则输出 0。补全① 和 ② 处的代码。


#include <iostream>
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;
    if (①) {
        if(②){
            cout << 1;
            return 0;
        }
    }
    if (a >= 0) {
        if(b < 0){
            cout << 1;
            return 0;
        }
    }
    cout << 0;
    return 0;
}


          

          

          

          
3、

下列关于 C++ 语言中变量的叙述,不正确的是( )

          

          

          

          
4、 运行以下程序,输出的结果是()


#include <iostream>
using namespace std;
int main() {
    cout << "Hello" << " ";
    cout << "World";
    return 0;
}


          

          

          

          
5、下面代码实现的是判断n是否是 质数 的功能,补全 ① 和② 处的代码。
#include<iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    ______①_______
    for (int i = 2; i < n; i++) {
        if (____②____) {
            isprime = false;
            break;
        }
    }
    cout << isprime << endl;
    return 0;
}


          

          

          

          
6、

C++中,表示 布尔数据类型的关键字是( )

          

          

          

          
7、 在以下代码中,如果想让 result 等于 a与 b 的和,请补全以下代码。( )


int a = 5;
int b = 3;
int result;
result = _①_;
cout << result << endl;


          

          

          

          
8、 执行以下代码段,输出的结果是()


#include <iostream>
using namespace std;
int main() {
    int x = 10;
    if (x > 5) {
        cout << "x is greater than 5" << endl;
    } else if (x < 5) {
        cout << "x is less than 5" << endl;
    } else {
        cout << "x is equal to 5" << endl;
    }
    return 0;
}


          

          

          

          
9、 编写程序,计算区间 100∼n 之间的所有整数(100<n≤999),数字 x(0<x<9)共出现的次数,补全①、② 和 ③ 处的代码。例如: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++) {
        _①_
        int g, s, b;
        g = a % 10;
        _②_
        _③_
        if (g == x) {
            cnt++;
        }
        if (s == x) {
            cnt++;
        }
        if (b == x) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


          

          

          

          
10、 执行以下代码,输出的结果是()


int x = 5, y = 3;
cout << (x > y);


          

          

          

          
11、 执行以下程序段,输出的结果是()


for (int j = 1; j <= 6; j++) {
    if (j % 3 == 0) {
        break;
    }
    cout << j << " ";
}


          

          

          

          
12、

C++ 中,可以用来比较两个变量的值是否相等的运算符是( )

          

          

          

          
13、

C++ 中,输入指令是( )

          

          

          

          
14、

声明一个整型变量 age 的正确方式是( )

          

          

          

          
15、 输出 1 到 10 之间的所有偶数,请补全以下代码。( )


#include <iostream>
using namespace std;
int main() {
    for (int i = 1; i <= 10; i++) {
        if (_①_) {
            cout << i << endl;
        }
    }
    return 0;
}


          

          

          

          

判断题


1、

C++ 中,整型 int 可以用来存储小数

                    
2、

C++ 中,变量名可以以数字开头

                    
3、

C++ 中,if 语句后面的条件表达式必须用小括号括起来

                    
4、

C++ 中,变量声明后,如果不初始化,其值是确定的

                    
5、

C++ 中,for 循环至少执行一次

                    

编程题