Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "iostream"
- #include "fstream"
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "Russian");
- ofstream out("fibonacci.dat", ios::binary);
- int n;
- cout << "n = ";
- cin >> n;
- int a1 = 1, a2 = 1, a;
- //записываем данные в двоичный файл
- for (int i = 1; i <= n; ++i)
- {
- if (i <= 2) { a = 1; out.write((char*)&a, sizeof(a)); }
- else
- {
- a = a1 + a2;
- a1 = a2;
- a2 = a;
- out.write((char*)&a, sizeof(a));
- }
- }
- out.close();
- ifstream in("fibonacci.dat", ios::binary);
- cout << "Номер:" << '\t' << "Элемент:" << endl;
- int k = 0;
- in.seekg(0);
- while (in.peek() != EOF)
- {
- ++k; in.read((char*)&a, sizeof(int));
- if (k % 3 != 0) cout << k << '\t' << a << endl;
- }
- in.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement