Advertisement
Abelsor

VPL_S6_E3

Apr 12th, 2023
704
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include<iostream>
  2. #include<limits.h>
  3. using namespace std;
  4.  
  5. /*Función que devuelve el valor del máximo en el vector V de "tam" elementos*/
  6. int maximo(int V[], int tam){
  7.     int mayor = 0;
  8.     for(int i=0 ; i<tam ; i++)
  9.     {
  10.         if(V[i] > mayor){
  11.             mayor=V[i];
  12.         }
  13.     }
  14.     return mayor;
  15. }
  16.  
  17. /*Función que devuelve el valor del mínimo en el vector V de "tam" elementos*/
  18. int minimo(int V[], int tam){
  19.     int menor = INT_MAX;
  20.     for(int i=0 ; i<tam ; i++)
  21.     {
  22.         if(V[i] < menor){
  23.             menor=V[i];
  24.         }
  25.     }
  26.     return menor;
  27. }
  28.  
  29. /*Función auxiliar - Lectura de un vector*/
  30. void leerVector(int X[], int n){
  31.     int i;
  32.     for(i=0;i<n;i++) cin>>X[i];
  33. }
  34.  
  35. int main(){
  36.      /*---NO MODIFICAR El MAIN*/
  37.     int opcion,n;
  38.     cin>>opcion;
  39.     cin>>n;
  40.     int a[n];
  41.     if(opcion==1){
  42.         leerVector(a,n);
  43.         cout<<maximo(a,n);
  44.     }
  45.     if(opcion==2){
  46.         leerVector(a,n);
  47.         cout<<minimo(a,n);
  48.     }
  49.     return 0;
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement