chanellhuntley6785 chanellhuntley6785
  • 25-11-2020
  • Computers and Technology
contestada

Write a function gcd(x, y) that returns the greatest common divisor of the parameters x and y. Use the Euclidean algorithm to do this. Return None if the gcd does not exist(i.e., if both parameters are 0)

Respuesta :

tonb
tonb tonb
  • 25-11-2020

Answer:

function gcd(x,y) {

if (!y && !x) return 'None';

if (!y) return x;

return gcd(y, x%y);

}

console.log(gcd(462, 910));

console.log(gcd(0, 0));

console.log(gcd(32, 40));

Explanation:

This example is in javascript.

Answer Link

Otras preguntas

The Supreme Court ruled that the .... was unconstitutional on the grounds that its provisions were local matters and should be regulated by the states. a. Feder
Both the US and Soviet Union joined the __________ after WWII
Terry uses 3 cups of pumpkin seeds to decorate the tops of 12 loaves of bread. She puts an equal amount of seeds on each loaf. How many cups of pumpkin seeds do
A dressmaker has 24 buttons. He needs 3 buttons to make one dress. How many dresses can he make with 24 buttons
every 1/2 hour naomi stretches her neck; every 1/3 hour she stretches her legs; every 1/6 hour she stretches her arms. which parts of her body will naomi stretc
McCarthyism was successful because Americans feared a. the Cold War. c. Communism. b. Soviet domination. d. all of the above.
Lucy's dog weighs nine and seventy five hundredths kilograms . Write in expanded form.
what surrounds all cells and control what enter and leaves the cell
Why did John Calvin write the Institutes of the Christian Religion? to refute the teachings of Martin Luther to defend a king’s right to an annulment to support
On a speed-time graph, a horizontal line shows the change in speed is ____.