The number in a sequence 1 1 2 3 5 8 13 21 . . . . . . . are called Fibonacci numbers. Write a C program using a for loop to calculate and print the first 20 Fibonacci number.

#include<stdio.h>
#include<conio.h>

void main()
{
    int x,y,n,i,z;
    clrscr();
    printf("Please enter a value:");
    scanf("%d",&n);
    printf("\n\n");
    x=0;
    y=1;

    for(i=1;i<=n;i++)
    {
        z=x+y;
        printf("%d  ",z);
        y=x;
        x=z;
    }

    getch();
}
Next Post Previous Post
No Comment
Add Comment
comment url