Fibonacci series | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Fibonacci series

Can someone help me to make a Fibonacci series program in C++????

18th Jul 2016, 3:55 PM
Mayank Singh
Mayank Singh - avatar
6 Answers
+ 6
I think this is the code which can help you: Program : #include<iostream> using namespace std; int main() { int range, first = 0, second = 1, fibonicci=0; cout << "Enter Range for Terms of Fibonacci Sequence: "; cin >> range; cout << "Fibonicci Series upto " << range << " Terms "<< endl; for ( int c = 0 ; c < range ; c++ ) { if ( c <= 1 ) fibonicci = c; else { fibonicci = first + second; first = second; second = fibonicci; } cout << fibonicci <<" "; } return 0; } Output : Enter Range for Terms of Fibonacci Sequence: 5 Fibonicci Series upto 5 Terms 0 1 1 2 3
19th Jul 2016, 7:06 AM
Fardad Fateh
+ 3
#include <iostream> using namespace std; int main() { // Variable Declaration int counter, n; long last=1,next=0,sum; // Get Input Value cout<<"Enter the Number :"; cin>>n; //Fibonacci Series Calculation while(next<n/2) { cout<<last <<" "; sum=next+last; next=last; last=sum; } // Wait For Output Screen return 0; } goodluck !
18th Jul 2016, 4:21 PM
Karan Luther
Karan Luther - avatar
+ 2
Fib[0]=1; Fib[1]=1; if n>1 Fib[n]=Fib[n-1]+Fib[n-2]
18th Jul 2016, 6:05 PM
S1xe
S1xe - avatar
+ 2
For information, you can also find it n the answer of a question post les than 48h ago and with the search field in Code Playground
18th Jul 2016, 6:55 PM
Dorian
+ 1
#include<ikstream.h> void main() { int f1=0,f2=1,f,n; clear(); cout<<"enter the range"; Cin>>n; if(n<=1) cout<<n; else { cout<<f1; cout<<f2; for(i=2;i<=n;i++) { f=f1+f2; f1=f2; f2=f; cout<<f; } getch(); }
8th Jan 2017, 7:13 PM
Suryakant Sarraf
Suryakant Sarraf - avatar
+ 1
#include‹iostream› Using namespace std; Int main() { Int a,b,c,i; A=0; B=1; /*i am printing upto next 15 terms*/ For(i=1;i‹=15;i++) { Cout‹‹a‹‹" "; C=a+b; A=b; B=c; } Return 0; }
31st Jan 2017, 5:47 PM
Gatikrushna Mishra
Gatikrushna Mishra - avatar