English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

the greatest common devisor of two integer

2006-09-05 15:22:32 · 3 answers · asked by joechelbasti1428 1 in Computers & Internet Programming & Design

3 answers

An inefficient one.. Determine the smaller of the absolute values of the two integers. Initialize a variable that states 1 is the highest common divisor. Begin a for loop starting from 2 to the smallest absolute value of the two integers stepping by 1. Divide both integers at each iteration by the for variable. Or just test the remainders at each iteration, probably easiest to use the mod function. Change the common divisor variable to match the for variable if there is no remainder for both (ie mod=0 for both) at any iteration. At the end of the loop return the common divisor variable.

Oh yah, make sure neither integer is 0 first!

2006-09-05 15:36:18 · answer #1 · answered by Andy S 6 · 0 0

what's the terrific common Divisor of 412 and sixteen, utilising the Euclidean Algortithm? Divide the bigger of the two numbers with the help of the smaller. you recognize the thank you to do “gazintas”, don’t you? sixteen gazinta 412 25 circumstances, leaving a the remainder of twelve. In different words, 412 = sixteen * 25 + 12. 25 is the quotient, 12 is something. Now divide the smaller variety with the help of the above the rest. 12 gazinta sixteen one time with a the remainder of four. sixteen = 12 * a million + 4. a million is the quotient, 4 is something. Now you divide the previous the rest with the help of the 2d the rest: 12 = 4 * 3 + 0 This time something is 0 so we are performed. The final the rest is your answer, 4. 412 / 4 = 103 and sixteen / 4 = 4. No variety extra advantageous than 4 “gazinta” the two sixteen and 412 with a nil the rest, so we are performed.

2016-11-24 23:42:56 · answer #2 · answered by ? 4 · 0 0

http://en.wikipedia.org/wiki/Binary_GCD_algorithm

2006-09-05 20:36:43 · answer #3 · answered by cdg1111us 2 · 0 0

fedest.com, questions and answers