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

is a blue whale, rosebush, mushroom, algea, or pine tree a heterotroph or auto troph
can some1 help me with grade7s math?
The _______ in plants is directly responsible for absorbing light energy.
Should a president die in office, which official succeeds the president if the vice president is unable to assume the role? A.secretary of state B.first lady C.
What is the change that occurs when a substance changes from a gas to a liquid? Melting Boiling Evaporation Condensation
. In a famous speech, William Jennings Bryan A. refused to be allied with the so-called "silverists." B. declared his staunch support of the gold standard. C. r
What could I write about a New Years Resolution
Which of the following is not a listed provision in any of the treaties with Tribal Nations? Select the best answer choice. A)Friendship and military alliances
When two geologic plates are moving away from each other, a ______ can result.
in the late 1840s, what challenges did Mexicans living in territory ceded by Mexico face? A.outnumbering white settlers B.being forced into slavery C.having ine