Friday, November 23, 2012

WRITE A C PROGRAM TO GENERATE N FIBONACCI NUMBERS


/*  WRITE A C PROGRAM TO GENERATE N FIBONACCI NUMBERS */

#include<stdio.h>
#include<conio.h>
void main()
{
            int a=0,b=1,c,n,i;
            clrscr();
            printf("Enter the value of N : ");
            scanf("%d",&n);
            printf("\n%d\n%d",a,b);
            for(c=a+b,i=3;i<=n;c=a+b,a=b,b=c,i++)
                        printf("\n%d",c);
            getch();
}
/*
            =====OUTPUT=====

            Enter the value of N : 10

             The 10 Fibonacci Numbers Are...

            0
            1
            1
            1
            2
            3
            5
            8
            13
            21
*/

0 comments:

Post a Comment