recursive

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
include <iostream>
using namespace std;
int sumarray(int [],int);
int sumarray(int a[],int n)
{
if (n==1)return a[0];
else return(a,(n-1)+sumarray(a,n-1));
}
int main()
{
int a[]={6,3,2,8,-7,4};
cout<<sumarray(a,5)<<endl;

return 0;
}


im trying to understand the else return part if someone can help
the answers in 12 by the way
ok i fix it now is coming to 16
Last edited on
line 7 is wrong, which might be why you're not understanding it.

The correct output should be 16 (6+3+2+8-7+4 = 16)
Topic archived. No new replies allowed.