Pages

program to generate Fibonacci series using Recursive function in C

This program can generate Fibonacci series of any number:

Source Code:
#include <stdio.h>
#include <conio.h>

int fibo(int); //function prototype;
void main()
{
int i,n,r;
   printf("How many no:");
   scanf("%d",&n);
   printf("Fibonacci Series of %d number:\n", n);

   for(i = 0; i < n; i++)
   {
    r = fibo(i);
      printf("%d\t",r);
   }
   getch();
}

int fibo(int n)
{
int r;
   if(n == 0)
    return 0;
   else if(n == 1)
       return 1;
   else
   {
    r = fibo(n-1) + fibo(n-2);
      return (r);
   }
}

Output:
How many number: 6
Fibonacci Series of 6 number.
0 1 1 2 3 5


@msucil

Phasellus facilisis convallis metus, ut imperdiet augue auctor nec. Duis at velit id augue lobortis porta. Sed varius, enim accumsan aliquam tincidunt, tortor urna vulputate quam, eget finibus urna est in augue.

No comments:

Post a Comment