Thursday 6 September 2012

Loop control structure069

Write a program to print Fibonacci Series up to 'n', 'n' will be input by user.
N.B. : - 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233

#include <stdio.h>
#include <conio.h>
void main ( )
{
            int       p = 1, c = 1, f, n;
            clrscr ( );
            printf("\n\t\t\t Enter a number..:"); scanf("%d",&n);
           
            printf("\n\n\n\t The Fibonacci Series: - ");
            printf(" %d %d",p, c);
            f = p + c;
                                
            while ( f <= n )
            {                               
                           printf(" %d",f);
                           p = c;
                           c = f;
                           f = p + c;
            }
            getch ( );
}
Click here to contact us 

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...