Advertisement
AntonioVillanueva

Muestra elemento array si no existe

Feb 14th, 2016
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. bool existe(unsigned char *arreglo ,int index,unsigned char busca){
  6.  
  7.     while (--index>0 ){if (arreglo[index]==busca){return true;}}
  8.     return false;
  9. }
  10.  
  11. int main (){
  12.     unsigned char arreglo[]={10,11,11,12,13,12,14,15,50,50,51,99,99,100,80,70,70,70,81,69,69};//Iguales
  13.     //unsigned char arreglo[]={1,20,3,40,5,60,7,80,9,10,11,12,13,14,15,16,17,18,19,20,21};  //Diferentes
  14.         for (size_t index=0;index<sizeof (arreglo);index++){
  15.            
  16.             if ( !existe ( arreglo,index,arreglo[index]))
  17.                 {cout <<" index ["<<index<<"]= "<<(int)arreglo[index]<<endl;}          
  18.         }
  19.     return  0;
  20. }
  21.  
  22. /*
  23. Utilice un arreglo con un solo subindice para resolver el problema:
  24.  
  25. Lea 20 numeros, en donde cada uno se encuentre entre 10 y 100.
  26.  
  27. Mientras lee cada numero, desplieguelo solamente si no es un duplicado de un numero ya leido.
  28.  
  29. Prevenga el "peor de los casos ", en el cual todos los numeros son diferentes.
  30. !Utilice el menor tamaño del arreglo posible!
  31. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement