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

What is the difference between formal and informal socialization? Which is more instrumental in forming ones political beliefs?
Why did the United States largely shy away from imperialism prior to 1890?
What was the outcome of the 1990 Myanmar election? How did the government respond?
How did the not guilty verdict in Andrew Johnson's impeachment trial affect the balance of power within the federal government? A. The judicial branch gained n
Which statements about the Catholic Church's response to the Reformation are true? Choose all answers that are correct. a. The pope called the Council of Trent
Which statement describes a major reason that America entered World War I on the Allied side? a. President Wilson thought a declaration of war would help the st
In "My Father Is a Simple Man," what do the lines "and we too will come back / like the orange trees" contain? a. alliteration b. an allusion c. onomatopoeia d.
true or false the expression 5x - 3(2x-4) is equivalent to the expression 12-x
Why were the members of the Third Estate dissatisfied with their way of life under the Old Regime?
How can you prevent muscle mass loss as you age