C program to print Fibonacci series

This C program takes the number of terms in the Fibonacci series as input from the user and then prints entered number of terms of the Fibonacci series.

Program: Print Fibonacci series in C

#include<stdio.h>
int main()
{
    int n1=0 , n2=1, n3, i, n;
    printf("Enter the number of terms: ");
    scanf("%d",&n);
    printf("\n%d  %d",n1,n2);
    for(i=1;i<=n-2;++i)
    {
        n3=n1+n2;
        printf("  %d",n3);
        n1=n2;
        n2=n3;
    }
    printf("\n");
    return 0;
}

Output: Print Fibonacci series

Enter the number of terms: 9

0  1  1  2  3  5  8  13  21

For more programming articles and code snippets, visit programming articles.

About ᴾᴿᴼᵍʳᵃᵐᵐᵉʳ

Linux and Python enthusiast, in love with open source since 2014, Writer at programming-articles.com, India.

View all posts by ᴾᴿᴼᵍʳᵃᵐᵐᵉʳ →

Leave a Reply

Your email address will not be published. Required fields are marked *