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

Check out this stream