Advertisement
s00rk

C++ Ruben Tarea2

Sep 15th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int tam, val = 0, j = 0;
  8.     int *A, *B;
  9.     bool existe = false, existe2 = false;
  10.     cout << "Tamaño del Vector: ";
  11.     cin >> tam;
  12.  
  13.     A = new int[tam];
  14.     B = new int[tam];
  15.     cout << "Arreglo A:" << endl;
  16.     for(int i = 0; i < tam; i++){
  17.         A[i] = int(50*rand()/(RAND_MAX + 1.0))+1;
  18.         B[i] = 0;
  19.         cout << A[i] << endl;
  20.     }
  21.    
  22.     for(int x = 0; x < tam; x++)
  23.     {
  24.         existe = false;
  25.         existe2 = true;
  26.         for(int i = (x+1); i < tam; i++)
  27.             if(A[x] == A[i] && !existe)
  28.                 existe = true;
  29.  
  30.         for(int i = 0; i < tam; i++)
  31.             if(A[x] == B[i] && existe && existe2)
  32.                 existe2 = false;
  33.  
  34.         if(existe)
  35.             B[j] = A[x];
  36.         j++;
  37.     }
  38.    
  39.     cout << endl << "Areglo B:" << endl;
  40.     for(int i = 0; i < tam; i++)
  41.         if(B[i] != 0)
  42.             cout << B[i] << endl;
  43.  
  44.     cin.get();cin.get();
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement