Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     //cout << "Hello world!" << endl;
  8.  
  9.     int v[] = {4,5,6,7,8,10};//inicializando
  10.     int v2[10]; //sin inicializar
  11.  
  12.  
  13.     int tam = sizeof(v)/sizeof(v[0]); //24/4
  14.     //cout <<"tamano del vector:" <<tam <<endl;
  15.  
  16.  
  17.     int x;
  18.     cout << "Escriba el dato a buscar:";
  19.     cin >> x;
  20.     int e = 0;
  21.     for(int i =0; i< tam;i++){
  22.         if(x == v[i]){
  23.             cout <<x<<" Se encuentra en:"<<i<<endl;
  24.             e = 1;
  25.         }
  26.     }
  27.  
  28.     if(e < 1){//si no encontro datos
  29.         cout << x<<"  no se encuentra en el vector"<<endl;
  30.     }
  31.  
  32.  
  33.  
  34.  
  35.     return 0;
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement