Computer Science, asked by aishwaryasangade1, 8 months ago

Write a program to find the nth term in the Fibonacci series using recursion. Note that the first 2 terms in the Fibonacci Series are 0 and 1.
INPUT & OUTPUT FORMAT:
Input consists of an integer.
Refer sample input and output for formatting specifications.
All text in bold corresponds to the input and the rest corresponds to output.
SAMPLE INPUT & OUTPUT:
5
The term 5 in the fibonacci series is 3

Answers

Answered by queensp73
1

Answer:

/*

* C Program to find the nth number in Fibonacci series using recursion

*/

#include <stdio.h>

int fibo(int);

 

int main()

{

   int num;

   int result;

 

   printf("Enter the nth number in fibonacci series: ");

   scanf("%d", &num);

   if (num < 0)

   {

       printf("Fibonacci of negative number is not possible.\n");

   }

   else

   {

       result = fibo(num);

       printf("The %d number in fibonacci series is %d\n", num, result);

   }

   return 0;

}

int fibo(int num)

{

   if (num == 0)

   {

       return 0;

   }

   else if (num == 1)

   {

       return 1;

   }

   else

   {

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

   }

}

Explanation:

hope it helps u

:)

Answered by ajinkyabiyani
3

Answer:

#include<stdio.h>

int fib (int);

int main ()

{

 int n, result;

 scanf ("%d", &n);

 result = fib (n - 1);

 printf ("The term %d in the fibonacci series is %d\n", n, result);

 return 0;

}

 

/* function for  recursive fibonocci call */

int fib (int n)

{

 if (n == 0)

   {

     return 0;

   }

 else if (n == 1)

   {

     return 1;

   }

 else

   {

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

   }

}

Explanation:

This is the right code and all cases are satisfied

Similar questions