Thursday 26 January 2012

Write a C program to print the Fibonacci Series upto to the first 'n' terms

#include<stdio.h>
#include<conio.h>
void main()
{
    int f=0, s=1, t, n, ct;
    clrscr();
    printf("Enter the value of 'n': ");
    scanf("%d",&n);
    printf("\nFibonacci series:\n");
    printf("%5d%5d", f, s);
    ct=3; //becoz we already displayed 2 values and we r going the third value
    while(ct<=n)
    {
        t=f+s;
        printf("%5d", t);
        f=s;
        s=t;
        ct++;
    }
    getch();
}

No comments:

Post a Comment