Gate
Exam
Programming
int get(int n)
{
if n<1 get(n-1);
get(n-3);
return (0);
}
If get(6) is called through main then how many times get() function is called?
Read Solution (Total 4)
-
- first time it checks the condition ,since condition not satisfied it executes else part and exits the function.
so only once it is called
- 10 years agoHelpfull: Yes(0) No(0)
- results in infinite loop run.. as no break condition is provided.
- 9 years agoHelpfull: Yes(0) No(0)
infinite times
1 ... get(6) excute else part it will call get (6-3) so
2 ....get(3) ...... excute else part it will call get (3-3) so
3 ... get(0)..... excute if part get(0-1)
4 ..get(-1) so it will never terminate ,will call for -2,-3,-4.........- 9 years agoHelpfull: Yes(0) No(0)
- After getting in condition n
- 9 years agoHelpfull: Yes(0) No(0)
Gate Other Question