#2527. 2024 CSP-J1 真题 · 阅读程序3

2024 CSP-J1 真题 · 阅读程序3

2024 CSP-J1 真题(120 分钟,总分 100 分)

阅读程序3(共 6 题,共 14.5 分)

1.

#include <iostream>
#include <cmath>
using namespace std;

int customFunction(int a, int b) {
    if (b == 0) {
        return a;
    }
    return a + customFunction(a, b-1);
}

int main() {
    int x, y;
    cin >> x >> y;
    int result = customFunction(x, y);
    cout << pow(result, 2) << endl;
    return 0;
}

当输入为“2 3”时,customFunction(2,3)的返回值为“64”。

{{ select(1) }}

  • 正确
  • 错误

2. 当b为负数时,customFunction(a,b)会陷入无限递归。

{{ select(2) }}

  • 正确
  • 错误

3. 当b的值越大,程序的运行时间越长。

{{ select(3) }}

  • 正确
  • 错误

4. 当输入为“5 4”时,customFunction(5,4)的返回值为()。

{{ select(4) }}

  • 5
  • 25
  • 250
  • 625

5. 如果输入x=3和y=3,则程序的最终输出为()。

{{ select(5) }}

  • "27"
  • "81"
  • "144"
  • "256"

6. 若将customFunction函数改为“return a+customFunction(a-1,b-1);”,并输入“3 3”,则程序的最终输出为()。

{{ select(6) }}

  • 9
  • 16
  • 25
  • 36