GESP C++ 真题 · 逐题精解
首页C++八级真题 › 2024年3月 › 第14题

GESP 2024年3月 C++八级 单选题 第14题

C++八级单选题2024年3月第14题

所属知识点:加法原理 难度要求:掌握 考频:中频

下面程序的输出为:
#include <iostream>
using namespace std;
int main() {
    int cnt = 0;
    for (int x = 0; x <= 10; x++)
        for (int y = 0; y <= 10; y++)
            for (int z = 0; z <= 10; z++)
                if (x + y + z == 15)
                    cnt++;
    cout << cnt << endl;
    return 0;
}

正确答案:B

题目解析
统计 0≤x,y,z≤10 且 x+y+z=15 的解数。无上限解数 C(17,2)=136;减去某变量≥11 的情形 3×C(6,2)=45(无重叠),得 136−45=91,选 B。

想系统刷完 GESP C++ 1~8 级真题,并查看每道题的逐题精讲?

进入 GESPPASS 开始练习