Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main(){
- srand(time(NULL));
- int N;
- do{
- cout << "Unesite prirodan broj N: ";
- cin >> N;
- }while(N < 0);
- fstream dat;
- dat.open("datoteka.dat", ios::in | ios::out | ios::binary);
- int broj1 = rand();
- int broj2;
- dat.write(reinterpret_cast<const char *>(&broj1), sizeof(int));
- cout << broj1 << " ";
- for(int i=0; i<N-1; i++){
- do{
- broj2 = rand();
- }while(broj2 > broj1);
- dat.write(reinterpret_cast<const char *>(&broj2), sizeof(int));
- broj1 = broj2;
- cout << broj2 << " ";
- }
- dat.close();
- dat.clear();
- dat.open("datoteka.dat", ios::in | ios::binary);
- while(1){
- break;
- dat.read((char*)&broj1, sizeof(broj1));
- if(dat.eof()) break;
- cout << broj1 << " ";
- }
- dat.close();
- dat.clear();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement