2024 年第 28 题判断题函数与递归普及/提高
程序(三):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 为负数时,customFunction(a,b)会陷入无限递归。( 填 √ 或 × )
考点拆解
递归函数
易错提醒
阅读程序题要按变量变化顺序手推,不要跳步
选择题要检查单位、边界和题目中的否定词