इस पृष्ठ में हम Print Fibonacci series in C++ में प्रिंट करेंगे, लेकिन program शुरू करने से पहले समझना होगा fibonacci series क्या होता है।
fibonacci series में, पहली संख्या और दूसरी संख्या का कुल , तीसरी संख्या होती है।
first number + second number = third number
इसे आप नीचे दिए गए Diagram से समझ सकते हैं –
इसका program नीचे दिया गया है –
#include<iostream.h>
#include<conio.h>
void main()
{
int first=0,second=1,next;
int num;
clrscr();
cout<<"Enter the number of terms in series:";
cin>>num;
cout<<first<<"\t"<<second;
int i=3;
while(i<=num)
{
next=first+second;
cout<<"\t"<<next;
first=second; // now first number is second
second=next; // and second number is next
i++;
}
getch();
}
OUTPUT
Enter the number of terms in series: 8
0 1 1 2 3 5
Related exercise