Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int fibonacchi(int n){
- int f0 = 0,
- f1 = 1,
- fn = 1;
- if(n<=1)
- return n;
- else{
- for(int i = 2;i<n;i++){
- f0=f1;
- f1=fn;
- fn = f0+f1;
- }
- }
- return fn;
- }
- int main(){
- int n = 0;
- cout<<"N: ";
- cin>>n;
- for(int i = 0;i<n;i++){
- cout<<fibonacchi(i)<<" ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement