最大公约数和最小公倍数

写了一段相关的代码,好久不写了

#include <iostream>
#include <exception>
#include <stack>

using namespace std;

int func(int a, int b) {
    if (a < b) {
        a = a ^ b;
        b = a ^ b;
        a = a ^ b;
    }
    while (b != 0) {
        int c = a % b;
        a = b;
        b = c;
    }
    return a;
}

int func2(int a, int b) {
    int c = func(a, b);
    return c * (a/c) * (b/c);
}

int main() {
    std::cout << "Hello, World!" << std::endl;

    cout << func(33, 44) << endl;
    cout << func2(33, 44) << endl;

    return 0;
}
原文地址:https://www.cnblogs.com/charlesblc/p/6431542.html