Advertisement
MeehoweCK

Untitled

Jun 5th, 2024
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. void fibonacci(std::ofstream& plik, const int n) {
  5.     int a{}, b{ 1 }, c{};
  6.     while ((b + c) < n) {
  7.         a = b;
  8.         b = c;
  9.         c = a + b;
  10.         plik << c << std::endl;
  11.     }
  12.  
  13.     plik.close();
  14. }
  15.  
  16. int main() {
  17.     std::cout << "Podaj liczbe naturalna: ";
  18.     int n;
  19.     std::cin >> n;
  20.     std::ofstream plik{ "fibonacci.txt" };
  21.     fibonacci(plik, n);
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement