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 v = Iwh for I
whats the fraction in simplest form- 9/12
What are 4 reasons the United states was unprepared for war with Britain.
Andy, Brenda, and Carla are running in a race. In how many different ways can the students finish in first, second, and third place? A) 2 ways B) 3 ways C) 4 wa
Which of the following is not a disaccharide?                 A)           sucrose                 B)            maltose                 C)            lactos
Andy, Brenda, and Carla are running in a race. In how many different ways can the students finish in first, second, and third place? A) 2 ways B) 3 ways C) 4 wa
7 apples weighs the same as 4 oranges 5 oranges weighs the same as 6 bananas Put the fruit in order of weight least to greatest
Siddhartha Gautama founded the religion of _____. A. Hinduism B. Buddhism C. Shintoism D. Zen
how did the discovery of glossopteris support wegner's continental drift hypothesis?
Which of these dams was built in China along the Yangtze River in order to provide hydroelectric power and flood control? Hoover Dam Three Gorges Dam Aswan Dam