AlbertMourato

Untitled

Dec 3rd, 2015
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. long long vetor[5005];
  4. int main(){
  5.     //freopen("in.txt", "r", stdin);
  6.     //freopen("out.txt", "w", stdout);
  7.     int n, nAnt = 2;
  8.     while(cin>>n){
  9.       vetor[1] = 1;
  10.       for(int i = nAnt; i<=n; i++){
  11.           vetor[i] = vetor[i-1]+vetor[i-2];
  12.       }
  13.       if(n>nAnt)nAnt = n;
  14.       cout<<"The Fibonacci number for "<<n<<" is "<<vetor[n]<<"\n";
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment