Write a complete C program that computes Fibonacci This prob

Write a complete C program that computes Fibonacci. This problem is similar to the previous programming exercise (assignment05pe03) except that the Fibonacci function must be recursive. Your fibonacci function should have a single argument. Re-use the same main function implemented in the previous programming exercise. Name your program assignment05pe04. c

Solution

//program is given below:

#include<stdio.h>

int fibonacci(int); //declaration of function

int main()
{
   int n,i;
   //prompt and accept limit of number of elements in series
printf(\"Enter the limit:\");
   scanf(\"%d\",&n);

   printf(\"Fibonacci series is:\ \");

for(i=0;i<n;i++)
   {
      printf(\"%d\ \", fibonacci(i));
   }

   return 0;
}
//recursive function for fibonacci series.
int fibonacci(int n)
{
   if (n== 0)
      return 0;
   else if (n==1)
      return 1;
   else
      return (fibonacci(n-1)+fibonacci(n-2));
}

/*output

sh-4.2$ main                                                                                                                                                             

Enter the limit:10                                                                                                                                                       

Fibonacci series is:                                                                                                                                                     0                                                                                                                                                                        1                                                                                                                                                                        1                                                                                                                                                                        2                                                                                                                                                                        3                                                                                                                                                                        5                                                                                                                                                                        8                                                                                                                                                                        13                                                                                                                                                                       21                                                                                                                                                                       34                                                                                                                                                                       

sh-4.2$

 Write a complete C program that computes Fibonacci. This problem is similar to the previous programming exercise (assignment05pe03) except that the Fibonacci f

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site