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);

Related Posts

More content you might like

Tutorial
javascript

Running JavaScript in the Browser Console

     $0.style.color = "red";
  • Write multi-line code directly in the console:

Dec 10, 2024
Read More
Tutorial
javascript

Mastering console.log Advanced Usages and Techniques

const user = { name: 'Bob', age: 25, active: true };
console.log(user); // Output: { name: 'Bob', age: 25, active: true }

console.table is an alternative to console.log that displays objects or arrays in a tabular format, making it easier to read structured data.

Sep 02, 2024
Read More
Code
javascript

Parse JSON String to Object

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Validate Password Strength

No preview available for this content.

Jan 26, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Be the first to share your thoughts!