#3421. [GESP202409 五级 C++] 第 3 题
[GESP202409 五级 C++] 第 3 题
对下面两个函数,说法错误的是( )。
int sumA(int n) {
int res = 0;
for (int i = 1; i <= n; i++) {
res += i;
}
return res;
}
int sumB(int n) {
if (n == 1)
return 1;
int res = n + sumB(n - 1);
return res;
}
{{ select(1) }}
sumA体现了迭代的思想。sumB采用的是递归方式。sumB函数比sumA的时间效率更高。- 两个函数的实现的功能相同。