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

map showing rice wheat?
Which statement describes an argumentative essay but not an explanatory essay ? a. the writer include historical data and examples as evidence b. the writer ci
3:4 is equivalent to ____:20.
Please answer fast.
I need help with this question
Why did the French take offense at the United States's relationship with Britain? (10 points) A. The U.S. was granted "most favored status" for trade with Br
The property of matter that resists changes in motion is called?
People's choices can have a positive or negative effect on their health. Describe one positive choice and one negative health choice a person could make. Be sur
Which leader dedicated his life to putting an end to apartheid in South Africa? Group of answer choices Mahatma Gandhi Nelson Mandela Winston Churchill William
BAD BOY CHAPTER 7-9 (100 points) In what environment was Walter most comfortable? A. alone in his room with a book B. on the baseball field with his team C. at