Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Ejercicio 8
- Dados tres números, indicar cuál es el central.
- */
- #include<iostream>
- using namespace std;
- int main()
- {
- int a,b,c;
- cout<<"Ingrese tres numeros"<<endl;
- cout<<"--> ";
- cin>>a;
- cout<<"--> ";
- cin>>b;
- cout<<"--> ";
- cin>>c;
- 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
- if((a>b and a<c) or (a<b and a>c)) //verificamos que a este en el centro en los posibles dos casos
- cout<<"El numero central es: "<<a;
- else if((b>a and b<c) or (b<a and b>c)) // Analogamente a la condicion anterior
- cout<<"El numero central es: "<<b;
- else if((c>b and c<a) or (c<b and c>a))
- cout<<"El numero central es: "<<c;
- }
- else
- cout<<"No existe un centro para estos numeros"<<endl; // En caso que los numeros no sean distintos
- }
Add Comment
Please, Sign In to add comment