J
jw
Hi all,i have a recursive function and in main for ex it takes 5 as a
parameter,n'll equal to 5 and than decrease.At the end it ll be 1 and
why doesnt the result equal to 1 because of this=>
if(n==1)
return 1
-----
int sum(int n){
if(n==1)
return 1;
else
return sum(n-1)+n;
}
void main(){
cout<<sum(5);
}
parameter,n'll equal to 5 and than decrease.At the end it ll be 1 and
why doesnt the result equal to 1 because of this=>
if(n==1)
return 1
-----
int sum(int n){
if(n==1)
return 1;
else
return sum(n-1)+n;
}
void main(){
cout<<sum(5);
}