Advertisement
kuba17ism

Ciąg fibonacciego

Oct 18th, 2020
620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     long long a = 0, b = 1;
  9.     int c;
  10.  
  11.     cout << "Podaj liczbe wyrazow ciagu fibonacciego" << endl;
  12.     cin >> c;
  13.  
  14.     ofstream wynik("wynik.txt");
  15.  
  16.     for (int i = 0; i < c; i++) {
  17.         if (i == 0) wynik << a << endl;
  18.         else if (i == 1) wynik << b << endl;
  19.         else {
  20.             b += a;
  21.             a = b - a;
  22.  
  23.             wynik << b << endl;
  24.         }
  25.     }
  26.  
  27.     wynik.close();
  28.  
  29.     cout << "Wyrazy ciagu zostaly zapisane w pliku wynik.txt" << endl;
  30.  
  31.     return 0;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement