DeveloperBreeze

Calculate Greatest Common Divisor (GCD) of Two Numbers

// Function to calculate the GCD of two numbers using the Euclidean Algorithm
function calculateGCD(a, b) {
    while (b !== 0) {
        const temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}

// Calculate and log the GCD of two numbers (e.g., 48 and 18)
const gcd = calculateGCD(48, 18);
console.log('GCD of Two Numbers:', gcd);

Continue Reading

Handpicked posts just for you — based on your current read.

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!