Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
715 B
1
Indexable
Never
//14. Hacer un programa para calcular el mcm(mínimo común múltiplo) de A, B;
//dos números enteros, donde mcm(A, B) = (AxB) / MCD
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int aux, n1, mcm, n2, resto = 1, MCD = 0;
    cout << "Introduce un numero: ";
    cin >> n1;
    cout << "Introduce otro numero: ";
    cin >> n2;
    mcm = n1 * n2;
    if (n1 < n2)
    {
        aux = n1;
        n1 = n2;
        n2 = aux;
    }
    while (resto != 0)
    {

        MCD = n1 / n2;
        resto = n1 % n2;
        n1 = n2;
        n2 = resto;
    }
    mcm = mcm / MCD;
    cout << MCD << endl;
    cout << "El mcm es: " << mcm << endl;
    return 0;
}