给你一个数组,请用递归计算所有元素的总和。 编写函数 int arrSum(int n),其中 n 表示数组中元素的个数。
int arrSum(int n)
n
n == 0
0
a[n] + arrSum(n-1)
5 1 2 3 4 5
15
对于 100%100\%100% 的数据,(1≤n≤1041 ≤ n ≤ 10^41≤n≤104),总和不会超过 intintint。
登录竞极 Ace,继续你的学习。