# W.A.P. C++

## WAP | CPP | Programs in C++ | C++ Solutions

### write a program to display fibonacci series upto n terms

Fibonacci series:The first two Fibonacci numbers are 0 and 1, and each remaining number is the sum of the previous two
e.g.: 0 1 1 2 3 5 8 13 21 ....
A number n is taken from user and the series is displayed upto nth term.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
1. #include<iostream.h>
2. #include<conio.h>
3. void main()
4. {
5. clrscr();
6. int a=0,b=1,c=0,n;
7. cout<<"Enter the number of terms you wanna see: ";
8. cin>>n;
9. cout<<a<<" "<<b<<" ";
10. for(int i=1;i<=n-2;i++)
11. {
12. c=a+b;
13. a=b;
14. b=c;
15. //Coding by: Snehil Khanor
16. //http://WapCPP.blogspot.com
17. cout<<c<<" ";
18. }
19. getch();
20. }

Saalim's innovations

in FOR statement "i<=n" will come :)

Deepak_Pappu

if i<=n is taken then the no of terms displayed is 17...!

ap

#include
using namespace std;
class fib
{
int i,n,f1,f2,f3;
public:
void get();
void put();
};
void fib::get()
{
cout<<"enter the no.";
cin>>n;
}
void fib::put()
{
f1=0,f2=1;
cout<<f1<<endl<<f2<<endl;
i=0;
while(i<n)
{
f3=f1+f2;
cout<<endl<<f3<<endl;
f1=f2;
f2=f3;
++i;
}
}
int main()
{
fib a1;
a1.get();
a1.put();
}
~

Kaushik Raja

#define fibonacci
#include
void main()
{
int a,b,c;
for(a=0,b=1,c=0;c<10;c=a+b,a=b,b=c)
cout<<c;
}

AM I CORRECT? BUT ITS NOT FOR N TERMS.. O/P S BASED ON VALUE OF C... PLS REPLY FOR ANY CORRECTION

Anonymous

can u specify #fibonacci jus like dat?? sorry if this is silly

Vishwa

use for(int i=0;i<=n-2;i++)

its show perfect series

Anonymous

The C Programs

the programs on this site are so useful for computer science students..........C program to convert given number of days into years,weeks and days

preeya

#include
#include
#include
int main()
{
int a,b,c,n;
a=0; b=1;
clrscr();
cout<<”enter number of terms (n)=”;
cin>>n;
cout<<Fibonacci series is”<<end1;
cout<<a<<setw(4)<<b;
int count=3;
while (count<=n)
{
c=a+b;
cout<<setw(4)<<c;
a=b;
b=c;
count++;
}
getch();
return 0;
}

Anonymous

can u plz post a program of fibonacci series using a another function
void fib(int n)

sameer gupta

#include
#include
void main()
{
clrscr();
{
int n,a=0,b=1,c,i;
cout<<"enter the value of n";
cin>>n;
cout<<"fibonacci series is=";
for(i=0;i<n;i++)
{
if(i<=1)
{
c=i;
}
else
c=a+b;
a=b;
b=c;
}
cout<<c<<",";
}
getch();
}

Anonymous

u r already printing the first two numbers

Jasir

See this one.. little more advanced..

Anonymous

actually whoever the programmer is doesn't know anything related to programming... i am atleast a 100 times better programmer....

Subash.M

#include
#include
void main()
{
int n,i,a=0,b=1,series;
cout<<"enter fibonnaci series";
for(i=0;i<n;i++)
{
if(i<=1)
series=i;
else
{
series=a+b;
a=b;
b=series;
}
cout<<series<<endl;
}
}

Hitesh Kumar

C++ Program to Generate Fibonacci series

Fibonacci Series is in the form of 0, 1, 1, 2, 3, 5, 8, 13, 21,...... To find this series we add two previous terms/digits and get next term/number.

Aswathy K.R

int a=-1,b=1,i,c,n;
cout<"enter limit:";
cin>>n;
for(i=0;i<n;i++)
{
c=a+b;
cout<<c<<"\n";
a=b;
b=c;
}

Venkat Shanthi

Very informative article.Thank you author for posting this kind of article .

http://www.wikitechy.com/view-article/Fibonacci-series-program-in-cpp

Both are really good,
Cheers,
Venkat

## Search

Here you'll find a wide range of programs' solution ranging from beginer level to advanced level.
All programs here are made, compiled and tested by me..and are running absolutely fine.. still if you find any bug in any program do let me know :)