Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- int main()
- {
- int tam, val = 0, j = 0;
- int *A, *B;
- bool existe = false, existe2 = false;
- cout << "Tamaño del Vector: ";
- cin >> tam;
- A = new int[tam];
- B = new int[tam];
- cout << "Arreglo A:" << endl;
- for(int i = 0; i < tam; i++){
- A[i] = int(50*rand()/(RAND_MAX + 1.0))+1;
- B[i] = 0;
- cout << A[i] << endl;
- }
- for(int x = 0; x < tam; x++)
- {
- existe = false;
- existe2 = true;
- for(int i = (x+1); i < tam; i++)
- if(A[x] == A[i] && !existe)
- existe = true;
- for(int i = 0; i < tam; i++)
- if(A[x] == B[i] && existe && existe2)
- existe2 = false;
- if(existe)
- B[j] = A[x];
- j++;
- }
- cout << endl << "Areglo B:" << endl;
- for(int i = 0; i < tam; i++)
- if(B[i] != 0)
- cout << B[i] << endl;
- cin.get();cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement