C Programming
Computer Programming

C Program using function to Display Fibonacci Sequence



Write a Program in C using function to Display Fibonacci Sequence

\* C Program using function to Display Fibonacci Sequence *\

# include < stdio.h >
# include < conio.h >
int   fibonaci(int, int, int) ;

int   main( )
{

int n, f1, f2, f = 0, i = 2 ;
printf(" Enter the last term of fibonaci series : ") ;
scanf("%d", &n) ;
f1 = 0 ;
f2 = 1 ;
printf("\n Fibonacci Series are : \n %d\t %d \t ", f1, f2 ) ;
fibonaci(f1, f2, n);
return (0) ;

}

int   fibonaci( int f1, int f2, int n )
{

int f ;
do
{
    f = f1 + f2 ;
    if( f <= n )
    {
        printf( "%d\t", f ) ;
        f1 = f2 ;
        f2 = f ;
    }
}
while(f <= n);
return (0) ;

}

Output of Program :

Output of C Program using function to Display Fibonacci Sequence