Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <float.h>
- // 9.15
- int main() {
- const std::string filename = "the9_15.txt";
- int n = 0, i = 0;
- double temp = 0.0f;
- std::cout << "Enter N: ";
- while (n <= 0)
- std::cin >> n;
- std::ofstream out(filename, std::ios::binary | std::ios::trunc);
- for (i = 0; i < n; i++) {
- std::cin >> temp;
- out.write(reinterpret_cast<const char*>(&temp), sizeof temp);
- }
- out.close();
- double max = -DBL_MAX;
- std::ifstream in(filename, std::ios::binary);
- for (i = 1; in; i++) {
- in.read(reinterpret_cast<char*>(&temp), sizeof temp);
- if ((i & 1) && temp > max)
- max = temp;
- }
- in.close();
- std::cout << "Result: " << max;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement