Ask Question

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

+4
Answers (1)
  1. 24 March, 23:13
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers