今天考完 CSP,有道题:
01 | #include<iostream>
02 | #include<cmath>
03 | using namespace std;
04 | int customFunction(int a, int b){
05 | if(b==0){
06 | return a;
07 | }
08 | return a + customFunction(a,b-1);
09 | }
10 |
11 | int main(){
12 | int x,y;
13 | cin >> x >> y;
14 | int result = customFunction(x,y);
15 | cout << pow(result,2) << endl;
16 | return 0;
17 | }
- 当
b 为负数时,customFunction(a, b) 会陷入无限递归。()
有说对的也有说是错的,下面说一下两派主要的理由:
1: 陷入无限递归就是说,在程序正常运行的情况下,无限执行一个程序。
2: 爆栈后,程序会结束,所以不属于无限递归(也基本不可能存在,只是在理想情况下来说)。
所以大家认为是对是错?