February 13, 2025
c-program c ++

C or C++ Program to Display Fibonacci Series

This article show the program to display Fibonacci series in C/C++.

C code to Display Fibonacci Series

#include
#include
#include
int main(){
clrscr();
long f0=0,f1=1,f2,i,n;

    cout<<"\" This program will display Fibonacci Series of n numbers.\""<<endl<<endl;

    xx:
    cout<<"How many numbers ?. Give a integer number."<<endl; 	cin>>n;

	if(n<0) {
	    cout<<"Negative number is not allow, Please give a integer number."<<endl; 	    goto xx; 	} 	if(n>46) {
	    cout<<"Greather than 46 is not allow"<<endl;
	    goto xx;
	}

    cout<<endl;
    cout<<"Fibonacci Series of 1 to "<<n<<" is:"<<endl;
    cout<<f1<<endl;

    for(i=1;i<n;i++) 
    {
	    f2=f0+f1;
	    cout<<f2<<endl;
	    f0=f1;
	    f1=f2;
	}

getch();
}

Rashedul Alam

I am a software engineer/architect, technology enthusiast, technology coach, blogger, travel photographer. I like to share my knowledge and technical stuff with others.

View all posts by Rashedul Alam →

Leave a Reply

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