Advertisement
Guest User

Pseudoslucajni

a guest
Feb 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4. #include <ctime>
  5. using namespace std;
  6.  
  7. int main(){
  8.     srand(time(NULL));
  9.     int N;
  10.     do{
  11.         cout << "Unesite prirodan broj N: ";
  12.         cin >> N;
  13.     }while(N < 0);
  14.     fstream dat;
  15.     dat.open("datoteka.dat", ios::in | ios::out | ios::binary);
  16.     int broj1 = rand();
  17.     int broj2;
  18.     dat.write(reinterpret_cast<const char *>(&broj1), sizeof(int));
  19.     cout << broj1 << " ";
  20.     for(int i=0;  i<N-1; i++){
  21.         do{
  22.             broj2 = rand();
  23.         }while(broj2 > broj1);
  24.         dat.write(reinterpret_cast<const char *>(&broj2), sizeof(int));
  25.         broj1 = broj2;
  26.         cout << broj2 << " ";
  27.     }
  28.     dat.close();
  29.     dat.clear();
  30.     dat.open("datoteka.dat", ios::in | ios::binary);
  31.     while(1){
  32.         break;
  33.         dat.read((char*)&broj1, sizeof(broj1));
  34.         if(dat.eof()) break;
  35.         cout << broj1 << " ";
  36.     }
  37.     dat.close();
  38.     dat.clear();
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement