Hi,
I am trying to find out the output of following recursive program using tracing:
int call(int num){
int x=1;
int y=0;
if(num>0){
x=x+num-1;
y=call(num-1)+2;
}
return x;
}
I have done following (replacing call( ) by c( ) for ease of typing):
c(5)
=> x=5 & y=c(4) +2
=> x=4 & y=c(3) +2 +2
=> x=3 & y=c(2) +2+2+2
=> x=2 & y=c(1)+2+2+2+2
=> x=1 & y=c(0)+2+2+2+2+2
So it should be 1. But the answer is not correct. Can somebody please guide me.
Zulfi.
I am trying to find out the output of following recursive program using tracing:
int call(int num){
int x=1;
int y=0;
if(num>0){
x=x+num-1;
y=call(num-1)+2;
}
return x;
}
I have done following (replacing call( ) by c( ) for ease of typing):
c(5)
=> x=5 & y=c(4) +2
=> x=4 & y=c(3) +2 +2
=> x=3 & y=c(2) +2+2+2
=> x=2 & y=c(1)+2+2+2+2
=> x=1 & y=c(0)+2+2+2+2+2
So it should be 1. But the answer is not correct. Can somebody please guide me.
Zulfi.