what will be the output of this program
void print (int n) { if (n>0) { printf(“hello”); print(n-1); } printf(“world”); }
It will print, N times “hello” and then by N+1 times “world”.
First it will call print function recursively N times and will print world after it comes out of the if block. “world” is printed N+1 times since when n ==0, it will not go inside if block and will print world and return.
First it will call print function recursively N times and will print world after it comes out of the if block. “world” is printed N+1 times since when n ==0, it will not go inside if block and will print world and return.
Facebook Comments
Pushker says
Its will print n times hello then n+1 times world because one failure.