Está en la página 1de 1

#include <iostream>

using namespace std;

// Implementacion de la funcion MCD


int MCD(int x, int y){

int ref;
int maxdiv;
x > y ? ref = x : ref = y;

for (int i{ 1 }; i < ref; i++)


{
if (x % i == 0 && y % i == 0)
maxdiv = i;
}
// Retorna Maxdiv y lo Almacena en MCD
return maxdiv;

int main()
{
//Lectura de los Numeros a evaluar
int x , y;
cout<<"INGRESE EL VALOR DE LOS NUMEROS QUE QUIERE CONOCER SU MCD" << endl;

cout<< "NUMERO 1: ";


cin >> x;
cout<< "NUMERO 2: ";
cin>> y;

// Evaluacion de los numeros

if ((x < 0) & (y < 0 )){


cout <<"error" << endl;
}else{
if ((x < 0) & (y > 0 )){
cout <<"error" << endl;
}else{
if ((x > 0) & (y < 0 )){
cout <<"error" << endl;
}else

// Despues de corroborar los numeros se llama a la funcion MCD


cout << "EL MAXIMO COMUN DIVISOR ES: " << MCD (x,y);
}
}

return 0;

}
// Fin Algoritmo :D

También podría gustarte