Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- using namespace std;
- int main()
- {
- int n=0, f0=0, f1=1, a=0, fn=0;
- cout<<"本程式將為你算出費波那西數列(Fibonacci Sequence) 請輸入要算到第n項\n";
- cin>>n;
- cout<<f0<<", "<<f1<<", ";
- do{
- fn=f0+f1;
- f0=f1;
- f1=fn;
- if(a!=n-3)
- cout<<fn<<", ";
- else
- cout<<fn<<endl;
- ++a;
- }while(a<=n-3);
- system("PAUSE");
- return 0 ;
- }
Advertisement
Add Comment
Please, Sign In to add comment