Fibonacci Series In C Mcq Exercise 3

int main

{

int num = 5, term1 = 0, term2 = 1, next_Term;

printf("Fibonacci Series: %d, %d, ", term1, term2);

for (int i = 1; i <= num; ++i)

{

next_Term = term1 + term2;

printf("%d, ", next_Term);

term1 = term2;

term2 = next_Term;

}

return 0;

}

Example


- 1, 1, 2, 3, 5

- 0, 1, 1, 2, 3, 5

- 0, 1, 1, 2, 3, 5, 8

- 0, 1, 2, 3, 5, 8

Explanation:

- The correct answer is option "c". The sequence corresponds to the Fibonacci series that the code generates, in which every number is the sum of the two numbers that came before it, starting from 0 to 1.

2. Which of the following statements about the Fibonacci series is true?

- It is an arithmetic progression.

- Each term is the sum of the two preceding ones.

- The series starts from 1 and 2.

- None of the above.

Explanation:

- The correct answer is option "b". This statement defines the Fibonacci sequence as true. In the Fibonacci sequence, each number is equal to the sum of the two numbers that came before it, starting with the third term.

3. Which of the following functions uses recursion to correctly return the nth Fibonacci number?

int fib(int num)

{

if (num <= 0)

return 0;

else if (num == 1)

return 1;

else

return (fib(num - 1) + fib(num - 2));

}

Example


int fib(int num)

{

if (num <= 1)

return num;

else

return (fib(num - 1) + fib(num - 2));

}

Example


int fib(int num)

{

if (num == 1)

return 1;

else if (num == 2)

return 1;

else

return (fib(num - 1) + fib(num - 2));

}

Example


int fib(int num)

{

if (num <= 1)

return num;

else if (num == 2)

return 2;

else

return (fib(num - 1) + fib(num - 2));

}

Example


Explanation:

- The correct answer is option "b". The basic cases (fib(0) and fib(1)) are handled appropriately, and for "num" greater than 1, the Fibonacci number is computed recursively by adding the results of fib(num - 1) and fib(num - 2). This method ensures accurate results for all valid inputs of num >= 0 and conforms to the standard definition of the Fibonacci sequence.

4. Which of the following statements of the Fibonacci function in recursive about is correct?

- It uses dynamic programming.

- It is more efficient than the iterative method.

- It has a time complexity of O(n).

- It has exponential time complexity.

Explanation:

- The correct answer is option "d". The naïve recursive Fibonacci function has exponential time complexity, or O(2^n). This is a result of each function call branching into two recursive calls, which causes the number of function calls to increase exponentially with n.

5. In the following recursive function for the Fibonacci sequence, what is the base case?

int fib(int num)

{

if (num <= 1)

return num;

return fib(num - 1) + fib(num - 2);

}

Example


- return fib(n - 1) + fib(n - 2)

- return 0

- n <= 1

- return 1

Explanation:

- The correct answer is option "d". The function is ensured to return num directly when num is 0 or 1, terminating the recursion and returning the correct Fibonacci number in such cases due to the condition (if (num = 1) return num;).

6. Which of these sequences does not have any relation to the Fibonacci sequence?

- Pell sequence

- Padovan sequence

- Geometric sequence

- Lucas sequence

Explanation:

- The accurate choice is alternative "c". The geometric progression stands out from the Fibonacci sequence as it follows a distinct generation rule based on a constant multiplication ratio, unlike sequences like Fibonacci, Lucas, Pell, and Padovan.

Input Required

This code uses input(). Please provide values below: