Ask Question
26 April, 11:05

Given an integer K, find the KthFibonacci number using recursion.

Write a function that accepts an integer K. The function should return Kth Fibonacci number using recursion.

Input:

10

where:

First line represents a value of K

Output:

55

+3
Answers (1)
  1. 26 April, 13:05
    0
    C program that find Fibonacci number using recursion

    #include

    int fib (int k) / *Function that returns Fibonacci number using recursion*/

    {

    if (k < = 1)

    return k;

    return fib (k-1) + fib (k-2); / /Recursive loop

    }

    int main () / /driver function

    {

    int k;

    printf ("Enter the Number for which we requires Fibonacci number-/n"); / *Taking input as k integer for finding its Fibonacci number*/

    scanf ("%d",&k);

    printf ("%d", fib (k)); / /Calling function fib

    return 0;

    }

    Output

    Enter the Number for which we requires Fibonacci number - 10

    55

    Function that returns Fibonacci number using recursion

    int fib (int k)

    {

    if (k < = 1)

    return k; / /returning Fibonacci Number

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

    }

    Here fib is the function of return type integer which accept a parameter k of integer type. In this function we are returning Fibonacci number.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Given an integer K, find the KthFibonacci number using recursion. Write a function that accepts an integer K. The function should return ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers