C
Programming and Technical
Programming
Program
Find the output for the following C program
fn f(x)
{ if(x<=0)
return;
else f(x-1)+x;
}
Read Solution (Total 5)
-
- Ans-x*(x+1)/2
Lets we take an example x=3
It goes to else and give. f(2)+3
f(2)=f(1)+2
f(1)=f(0)+1
f(0) goes to if and return 0 bcs here nothing is given....
So value will be 0+1+2+3=3(3+1)/2=6 - 10 years agoHelpfull: Yes(2) No(0)
- x*(x+1)/2
sum of n terms - 10 years agoHelpfull: Yes(1) No(0)
- here the return type is fn so it may cause a different result like fn(5).
- 10 years agoHelpfull: Yes(0) No(0)
- how ?? make me understand
- 10 years agoHelpfull: Yes(0) No(0)
- sum 1+2+upto x
- 8 years agoHelpfull: Yes(0) No(0)
C Other Question