#4226. 信息素养大赛C++初赛真题(二)

信息素养大赛C++初赛真题(二)

一、单选题(每题 5 分,共 75 分)

  1. 编写程序,计算区间100~n之间的所有整数 (100 < n <= 999),数字x (0 < x < 9)共出现的次数,补全①、②和③处的代码例如:100到109中,即100、101、102、103、104、105、106、107、108、109中,数字1出现了11次
    #include 
    using namespace std;
    int main() {
        int n, x;
        int 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;
    }
    

{{ select(1) }}

  • int a=i;s=a/10%10;b=a/100;
  • int g=i;s=g;b=g/10;
  • int cnt=i;s=cnt;b=cnt/100;
  • int a=n;s=a/10;b=a/10;

2.完全数是指一个数恰好等于除它本身之外的所有因数之和。例如:6的因数有1、2、3、6,除去6之外的因数之和为1+2+3=6,所以6为完全数。

编写程序,按从小到大的顺序寻找1到10000之间的完全数,输出第n个完全数,n的范围0 < n < 5。补全①、②和③处的代码。

#include <iostream>
using namespace std;
 
int main() {
    int n, sum = 0, num = 0;
    cin >> n;
    for (int i = 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(2) }}

  • sum+=i;sum==a;continue;
  • sum+=j;sum==a;break;
  • sum+=j;sum==a;continue;
  • sum+=i;sum==a;break;
  1. 下面哪个语句运行结果是9?

{{ select(3) }}

  • cout<<"5+4"<<endl;
  • cout<<5<<"+"<<4<<endl;
  • cout<<5+4<<endl;
  • cout>>5+4>>endl;
  1. 声明一个整型变量age的正确方式是()

{{ select(4) }}

  • int age
  • float age
  • string age
  • char age
  1. C++中有很多数据类型,以下可以定义存储浮点型变量的关键字是。

    {{ select(5) }}

  • int;
  • double;
  • char;
  • long long;
  1. 执行以下程序段,输入11,则输出的值是()
int x;
cin >> x;
cout << x + 2;

{{ select(6) }}

  • 10
  • 11
  • x
  • 13
  1. 在C++中,表示小于或等于的关系运算符是( )。

{{ select(7) }}

  • <
  • ==
  • <=
  • >
  1. 在C++中,可以计算两个数相除的余数的运算是( )。

{{ select(8) }}

  • ^
  • %
  • |
  • /
  1. 执行以下代码,输出的结果是( )。

    image

{{ select(9) }}

  • x is equal to 5
  • x is greater than 5
  • 无输出
  • x is less than 5

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

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

{{ select(10) }}

  • 2
  • true
  • 1
  • false

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

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

{{ select(11) }}

  • 1 2 3 4 5 6
  • 1 2
  • 1 2 3
  • 1 2 4 5 6

12.在C++中,可以比较两个变量的值是否相等的运算符是?() {{ select(12) }}

  • =
  • ===
  • ==
  • !=
  1. 在C++中,如何定义一个结构体?

    {{ select(13) }}

  • struct Student { int age; string name; };
  • class Student { int age; string name; };
  • typedef Student { int age; string name; };
  • new Student { int age; string name; };
  1. 现有数组定义为 int array[5] = {1};,数组 array 中的元素分别是()

{{ select(14) }}

  • 1 2 3 4 5
  • 0 0 0 0 1
  • 0 0 0 0 0
  • 1 0 0 0 0
  1. 以下结果为 true 的表达式是()

{{ select(15) }}

  • !( 1 && 0) && 1 < 0
  • (!0 && 1) < 7 || 6 < 7
  • !1 || 0 > 1
  • 1 >= !6 && 0 < !1

二、判断题(每题 5 分,共 10 分)

  1. 在C++中,整型 int可以用来存储小数。()

{{ select(16) }}

  • 正确
  • 错误
  1. 在C++中,break语句可以用来立即退出当前的循环。

{{ select(17) }}

  • 正确
  • 错误
  1. 在C++中,if语句后面的条件表达式必须用小括号括起来()。

{{ select(18) }}

  • 正确
  • 错误
  1. int a[4] = {11,22,33},输出 a[1]结果为 11()

{{ select(19) }}

  • 正确
  • 错误
  1. 在 C++语言中,标识符中可以有数字,但不能以数字开头()

{{ select(20) }}

  • 正确
  • 错误