Abelsor

Semana 3 - Ejercicio 8

Feb 15th, 2022 (edited)
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. /*
  2.                     Ejercicio 8
  3.     Dados tres números, indicar cuál es el central.
  4. */
  5.  
  6. #include<iostream>
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.     int a,b,c;
  13.    
  14.     cout<<"Ingrese tres numeros"<<endl;
  15.     cout<<"--> ";
  16.     cin>>a;
  17.     cout<<"--> ";
  18.     cin>>b;
  19.     cout<<"--> ";
  20.     cin>>c;
  21.    
  22.     if(a!=b and b!=c and a!=c){ //Primeramente verificamos si todos los numeros son distintos, en caso de cumplirse pasamos a la sgte condicion
  23.         if((a>b and a<c) or (a<b and a>c))  //verificamos que a este en el centro en los posibles dos casos
  24.             cout<<"El numero central es: "<<a;
  25.         else if((b>a and b<c) or (b<a and b>c)) // Analogamente a la condicion anterior
  26.             cout<<"El numero central es: "<<b;
  27.         else if((c>b and c<a) or (c<b and c>a))
  28.             cout<<"El numero central es: "<<c;
  29.     }
  30.    
  31.     else
  32.         cout<<"No existe un centro para estos numeros"<<endl; // En caso que los numeros no sean distintos
  33. }
Add Comment
Please, Sign In to add comment