Advertisement
PiotrJurek

Zad4

May 30th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int maxi=0;
  10.     int liczba;
  11.     srand(time(NULL));
  12.     ofstream zapis("plik.txt");
  13.     ifstream odczyt("plik.txt");
  14.  
  15.     if(zapis.is_open())
  16.     {
  17.         for(int i=0; i<10; i++)
  18.         {
  19.             zapis << rand()%1001+1000 << endl;
  20.         }
  21.     }
  22.     else
  23.     {
  24.         cout << "Zapis nieudany.";
  25.     }
  26.  
  27.     if(odczyt.is_open())
  28.     {
  29.         for(int i=0; i<10; i++)
  30.         {
  31.             odczyt >> liczba;
  32.             maxi = liczba>maxi ? liczba : maxi;
  33.         }
  34.     }
  35.     else
  36.     {
  37.         cout << "Odczyt nieudany.";
  38.     }
  39.  
  40.  
  41.     cout << "Najwieksza liczba w pliku to: " << maxi << endl;
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement