2024 年第 31 题阅读程序函数与递归普及/提高
程序(三):x=3,y=3 时程序的最终输出
题目
阅读下面的程序,回答问题。 #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; } 如果输入 x = 3 和 y = 3,则程序的最终输出为( )
考点拆解
递归函数
易错提醒
阅读程序题要按变量变化顺序手推,不要跳步
选择题要检查单位、边界和题目中的否定词