Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- #include <fstream>
- using namespace std;
- int main() {
- srand(time(0));
- rand();
- int n;
- do {
- cin>>n;
- }
- while(!(n>1000));
- ofstream dat1 ("datoteka1.txt");
- for(int i=0;i<n;i++) {
- dat1 << rand() << endl;
- }
- dat1.close();
- ofstream dat2 ("datoteka2.txt");
- for(int i=0;i<n;i++) {
- dat2 << rand() << endl;
- }
- dat2.close();
- int* dat1brojevi = new int[n];
- int* dat2brojevi = new int[n];
- ifstream datr1("datoteka1.txt");
- for(int i=0;i<n;i++) {
- datr1>>dat1brojevi[i];
- }
- datr1.close();
- ifstream datr2("datoteka2.txt");
- for(int i=0;i<n;i++) {
- datr2>>dat2brojevi[i];
- }
- datr2.close();
- ofstream dat3 ("zajednicki.txt");
- for(int i=0;i<n;i++) {
- for(int j=0;j<n;j++) {
- if(dat1brojevi[i] == dat2brojevi[j]) {
- dat3<<dat1brojevi[i]<<endl;
- break;
- }
- }
- }
- dat3.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement