Advertisement
skb50bd

Fibonacci

May 15th, 2015
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     short int n, i;
  8.  
  9.     cout << "Number of Fibonacci Terms: " << flush;
  10.     cin >> n;
  11.  
  12.     int ara[n];
  13.  
  14.     ara[0] = 0;
  15.     ara[1] = 1;
  16.  
  17.     cout << ara[0] << " " << ara[1] << " ";
  18.  
  19.     for (i = 2; i < n; i++)
  20.     {
  21.         ara[i] = ara[i - 2] + ara[i - 1];
  22.        
  23.         cout << ara[i] << " ";
  24.     }
  25.     cout << endl;
  26.  
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement