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

  • The console displays detailed error messages to help debug code.
  • Code written in the console is not saved.
  • Not suitable for large-scale projects or complex scripts.

Dec 10, 2024
Read More
Tutorial
javascript

Mastering console.log Advanced Usages and Techniques

const greeting = 'Hello, world!';
console.log(greeting); // Output: Hello, world!

You can log multiple values in a single console.log call by separating them with commas. This can be useful when you want to log related values together.

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!