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

There are six different candidates for governor of a state. in how many different orders can the names of the candidates be printed on a ballot?
Matt can walk 4 miles in an hour. How far can he walk in 3/4 of an hour
In line 15, Dr. Kennedy says, "Her husband used to be." This statement suggests that Amy Foster's husband. A. Has become a doctor B. Is dead C. Is a grateful pa
From Latin to English please, need a little help. Scivi copias (troops) Caesaris ab militibus inimicorum visas esse. So far i have: I knew the troops from Ca
Daisy sent gatsby a letter while he was at oxford informing him of her engagement to tom buchanan true or false?
Why does a cone us pi r^2 in its formula instead of B
–x(7x – 8) simplify and answer 70points and not solving for x
Just like other magnets, the Earth has A. two positively charged magnetic poles. B. only one magnetic pole. C. two negatively charged magnetic poles.
What is the interquartile range of the data set?
Yvette is considering taking out a loan with a principal of $16,200 from one of two banks. Bank F charges an interest rate of 5.7%, compounded monthly, and requ