Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Create a function to calculate the greatest common divisor (GCD) of two numbers.

Medium

Problem Statement

Create a function to calculate the greatest common divisor (GCD) of two numbers.

Sample Input

a = 48, b = 18

Sample Output

6

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
// Calculate GCD using Euclidean algorithm function gcd(a, b) { } console.log(gcd(48, 18));
Log in or sign up to run or submit your code.Log inSign up
Input
a = 48, b = 18
Expected Output
6