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

In 1668, Francesco Redi conducted an experiment with jars of meat. This experiment was noteworthy because it _____.
Which best describes the purpose of the Electoral College in the United States? chooses the winner of an election if the popular vote is disputed reduces the nu
Which word does not suggest a second appearance? A. disgorge B. efface C. recapitulation D. regurgitate
How do I do this? Can someone fill in the blanks
Which enzyme is responsible for facilitating the hydrogen bonding between nucleotides in a new DNA molecule?
During which of the following processes do vesicles sometime fuse with lysosomes
What's 2/34 simplified
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
why is 16:14 and 64:60 not equivalent
How do I do this? Can someone fill in the blanks