Sunday 21 October 2012

Function037

The sequence of Fibonacci numbers is defined as below: f(i)=f(i-1)+f(i-2) with f(0)=1 and f(1)=1. Develop a C program to calculate and display Fibonacci numbers. 

#include <stdio.h>
#include <conio.h>
void main ( )
{                      
        int     n, i, t;
        clrscr ( );
               
        printf("\n\n\n Enter the number of terms of the fibonacci series..:"); scanf("%d",&n);
        printf("\n\n\n OUTPUT....: ");
        for ( i = 0; i < n; i++ )
        {                                
                  t = fibo ( i );
                  printf("%d, ",t);
        }
        getch ( );
}               
                            
int fibo ( int     n )
{                           
        if ( n == 0 || n == 1 )
        {                                
                   return 1;
        }
        return fibo ( n - 1 ) + fibo ( n - 2 );
}
Click here to contact us

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...