W.A.P. C++

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

Snehil Khanor's Binary Log

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. }

18 comments:

Saalim's innovations April 24, 2011 at 8:34 PM  

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

Deepak_Pappu June 10, 2011 at 7:59 AM  

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

Unknown August 2, 2011 at 12:58 PM  

#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 October 8, 2011 at 12:09 PM  

#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 November 20, 2011 at 6:04 PM  

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

David Prasad January 12, 2012 at 9:00 AM  

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

its show perfect series

Anonymous February 15, 2012 at 8:04 PM  

it shows correct answers.. thanks

The C Programs May 23, 2012 at 5:59 PM  

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 September 6, 2012 at 7:59 PM  

#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 November 28, 2012 at 8:42 PM  

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

Unknown April 16, 2013 at 3:11 AM  

#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 September 2, 2013 at 7:05 PM  

u r already printing the first two numbers

Jasir September 18, 2013 at 11:31 PM  

See this one.. little more advanced..

Anonymous October 2, 2013 at 6:01 PM  


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

Subash.M November 27, 2014 at 6:32 PM  

#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 December 13, 2015 at 12:50 AM  

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.

Unknown March 21, 2016 at 11:21 PM  

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;
}

Unknown November 15, 2016 at 10:34 AM  

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

About WAP C++

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 :)

Followers

Subscribe via email

Enter your email address:

Delivered by FeedBurner

my Binary Log

Blog Archive



eXTReMe Tracker