2024 年第 29 题判断题函数与递归普及/提高
程序(三):b越大运行时间是否越长
题目
阅读下面的程序,回答问题。 #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; } 判断题:当 b 的值越大,程序的运行时间越长。( 填 √ 或 × )
考点拆解
递归函数
易错提醒
阅读程序题要按变量变化顺序手推,不要跳步
选择题要检查单位、边界和题目中的否定词