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 outdat1 ("prva.txt");
- for(int i=0;i<n;i++) {
- outdat1 << rand()%32767 << endl;
- }
- outdat1.close();
- ofstream outdat2 ("druga.txt");
- for(int i=0;i<n;i++) {
- outdat2 << rand()%32767 << endl;
- }
- outdat2.close();
- int* brojevidat1= new int[n];
- int* brojevidat2 = new int[n];
- ifstream indat1("prva.txt");
- for(int i=0;i<n;i++) {
- indat1>>brojevidat1[i];
- }
- indat1.close();
- ifstream indat2("druga.txt");
- for(int i=0;i<n;i++) {
- indat2>>brojevidat2[i];
- }
- indat2.close();
- ofstream dat3 ("zajednickibrojevi.txt");
- for(int i=0;i<n;i++) {
- for(int j=0;j<n;j++) {
- if(brojevidat1[i] == brojevidat2[j]) {
- dat3<<brojevidat1[i]<<endl;
- break;
- }
- }
- }
- dat3.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement