Advertisement
DasShelmer

9.3.15

Mar 28th, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <float.h>
  5.  
  6. // 9.15
  7. int main() {
  8.     const std::string filename = "the9_15.txt";
  9.  
  10.     int n = 0, i = 0;
  11.     double temp = 0.0f;
  12.  
  13.  
  14.     std::cout << "Enter N: ";
  15.     while (n <= 0)
  16.         std::cin >> n;
  17.  
  18.     std::ofstream out(filename, std::ios::binary | std::ios::trunc);
  19.     for (i = 0; i < n; i++) {
  20.         std::cin >> temp;
  21.         out.write(reinterpret_cast<const char*>(&temp), sizeof temp);
  22.     }
  23.     out.close();
  24.  
  25.     double max = -DBL_MAX;
  26.  
  27.     std::ifstream in(filename, std::ios::binary);
  28.     for (i = 1; in; i++) {
  29.         in.read(reinterpret_cast<char*>(&temp), sizeof temp);
  30.  
  31.         if ((i & 1) && temp > max)
  32.             max = temp;
  33.     }
  34.     in.close();
  35.  
  36.     std::cout << "Result: " << max;
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement