Write a C Program to generate and print first N FIBONACCI numbers.

#include<stdio.h>
#include<conio.h>
main()
{
    int i=3,fib1=0,fib2=1,fib3,n;
    clrscr();
    printf("\nHow many terms?");
    scanf("%d",&n);
    printf("%d\t%d\t",fib1,fib2);
    for(i=3;i<=n;i++)
    {
    fib3=fib1+fib2;
    printf("\t%d",fib3);
    fib1=fib2;
    fib2=fib3;
    }
    getch();
    return;
}

No comments:

Post a Comment