Skip to content
This repository was archived by the owner on Jun 26, 2022. It is now read-only.

algo:Added GCD algorithm of two numbers a and b #158

Merged
merged 1 commit into from
Jan 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions js/sahil9001_gcdalgo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
let euclideanAlgorithm = function (A, B) {
// Make input numbers positive.
const a = Math.abs(A);
const b = Math.abs(B);

// To make algorithm work faster instead of subtracting one number from the other
// we may use modulo operation.
return (b === 0) ? a : euclideanAlgorithm(b, a % b);
}


//Taking two numbers
let a = 20, b = 10;
console.log("GCD of " + a + " " + b + " is " + euclideanAlgorithm(a, b));