Fibonacci series:The first two Fibonacci numbers are 0 and 1, and each remaining number is the sum of the previous two
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
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 :)
- #include<iostream.h>
- #include<conio.h>
- void main()
- {
- clrscr();
- int a=0,b=1,c=0,n;
- cout<<"Enter the number of terms you wanna see: ";
- cin>>n;
- cout<<a<<" "<<b<<" ";
- for(int i=1;i<=n-2;i++)
- {
- c=a+b;
- a=b;
- b=c;
- //Coding by: Snehil Khanor
- //http://WapCPP.blogspot.com
- cout<<c<<" ";
- }
- getch();
- }