orlandoju

ejer6_tp6

May 31st, 2022
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. /*se ingresa por teclado un vector de 10 elementos todos distintos entre sí. Luego eliminar el valor máximo y desplazar todos los elementos un lugar.
  2.  
  3. Ejemplo:    
  4. Vector → {1 3 9 1 4 6 2 0 5 7 }, quedará → {1 3 1 4 6 2 0 5 7}
  5. Nota: No mostrar el último elemento del vector.*/
  6.  
  7. #include <iostream>
  8.  
  9. using namespace std;
  10.  
  11. int main (void){
  12.  
  13. const int valor=10;
  14. int vecnum[10];
  15. int i,valormax,posicionmax;
  16.  
  17.  
  18. cout<<"ingrese los valores: "<<endl;
  19. for (i=0 ; i<valor; i++){
  20.         cout<<" Valor: "<<endl;
  21.         cin>>vecnum[i];
  22. }
  23.  
  24. for(i=0; i<valor; i++){
  25.     if (i==0){
  26.     valormax=vecnum[i];
  27.     }
  28.     else if(vecnum[i] >valormax)
  29.     valormax=vecnum[i];
  30.     posicionmax=i;
  31. }
  32. cout<<"mostrar valor max: "<<valormax<< endl;
  33. //vecnum[3]=vecnum[posicionmax];
  34. for(i=0; i<valor ; i++){
  35.     if(vecnum[i]==valormax){
  36.         vecnum[i]=vecnum[9];
  37.  
  38.     }
  39. }
  40. for(i=0; i<9;i++)
  41. {
  42.     cout<<"los numeros sin "
  43.           "el mayor son: "<<vecnum[i]<<endl;
  44. }
  45.  
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment