Advertisement
s00rk

C++ Ruben Tarea3

Sep 15th, 2012
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. void imprimir(int *A, int tam)
  6. {
  7.     for(int i = 0; i < tam; i++)
  8.         if(A[i] > 0)
  9.             cout << A[i] << endl;
  10. }
  11.  
  12. bool eliminar(int *A, int x, int tam)
  13. {
  14.     bool resp = false;
  15.     for(int i = 0; i < tam; i++)
  16.         if(A[i] == x)
  17.         {
  18.             for(int j = i; j < tam; j++)
  19.                 A[j] = A[j+1];
  20.             resp = true;
  21.         }
  22.     return resp;
  23. }
  24.  
  25. int main()
  26. {
  27.     int tam, x = 0;
  28.     int *A;
  29.     cout << "Tamaño del Vector: ";
  30.     cin >> tam;
  31.  
  32.     A = new int[tam];
  33.     for(int i = 0; i < tam; i++)
  34.         A[i] = int(50*rand()/(RAND_MAX + 1.0))+1;
  35.    
  36.     imprimir(A, tam);
  37.    
  38.     do
  39.     {
  40.         cout << "Ingresa el valor a eliminar: (Salir = 0): ";
  41.         cin >> x;
  42.         if(x != 0)
  43.         {
  44.             if(eliminar(A, x, tam))        
  45.                 imprimir(A, tam);
  46.             else
  47.                 cout << "El elemento no fue encontrado en el arreglo" << endl;
  48.         }
  49.     }while(x != 0);
  50.    
  51.    
  52.     cin.get();cin.get();
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement