# YOU CAN DOWNLOAD 200+ SUBJECTS PDF BOOK FOR COMPETITIVE EXAMINATIONS

## Data Structure Questions and Answers-Fibonacci using Recursion

Question 11 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER] |

What is the output of the following code?

int fibo(int n) { if(n == 1) return 0; else if(n == 2) return 1; return fibo(n - 1) + fibo(n - 2); } int main() { int n = 5; int ans = fibo(n); printf("%d", ans); return 0; }

1 | |

2 | |

3 | |

5 |

Question 11 Explanation:

The program prints the 5th fibonacci number, which is 3.

Question 12 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER] |

How many times will the function fibo() be called when the following code is executed?

int fibo(int n) { if(n == 1) return 0; else if(n == 2) return 1; return fibo(n - 1) + fibo(n - 2); } int main() { int n = 5; int ans = fibo(n); printf("%d", ans); return 0; }

5 | |

6 | |

8 | |

9 |

Question 12 Explanation:

The function fibo() will be called 9 times, when the above code is executed.

Question 13 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER] |

What is the output of the following code?

int fibo(int n) { if(n == 1) return 0; else if(n == 2) return 1; return fibo(n - 1) + fibo(n - 2); } int main() { int n = 10; int ans = fibo(n); printf("%d", ans); return 0; }

21 | |

34 | |

55 | |

13 |

Question 13 Explanation:

The program prints the 10th fibonacci number, which is 34.

There are 13 questions to complete.