1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
MariettaO [177]
3 years ago
11

5. The recursive algorithm given below can be used to compute gcd(a, b) where a and b are non-negative integer, not both zero.

Mathematics
1 answer:
s2008m [1.1K]3 years ago
6 0

Implementating the given algorithm in python 3, the greatest common divisors of <em>(</em><em>124</em><em> </em><em>and</em><em> </em><em>244</em><em>)</em><em> </em>and <em>(</em><em>4424</em><em> </em><em>and</em><em> </em><em>2111</em><em>)</em><em> </em>are 4 and 1 respectively.

The program implementation is given below and the output of the sample run is attached.

def gcd(a, b):

<em>#initialize</em><em> </em><em>a</em><em> </em><em>function</em><em> </em><em>named</em><em> </em><em>gcd</em><em> </em><em>which</em><em> </em><em>takes</em><em> </em><em>in</em><em> </em><em>two</em><em> </em><em>parameters</em><em> </em>

if a>b:

<em>#checks</em><em> </em><em>if</em><em> </em><em>a</em><em> </em><em>is</em><em> </em><em>greater</em><em> </em><em>than</em><em> </em><em>b</em>

return gcd (b, a)

<em>#if</em><em> </em><em>true</em><em> </em><em>interchange</em><em> </em><em>the</em><em> </em><em>Parameters</em><em> </em><em>and</em><em> </em><em>Recall</em><em> </em><em>the</em><em> </em><em>function</em><em> </em>

elif a == 0:

return b

elif a == 1:

return 1

elif((a%2 == 0)and(b%2==0)):

<em>#even</em><em> </em><em>numbers</em><em> </em><em>leave</em><em> </em><em>no</em><em> </em><em>remainder</em><em> </em><em>when</em><em> </em><em>divided</em><em> </em><em>by</em><em> </em><em>2</em><em>,</em><em> </em><em>checks</em><em> </em><em>if</em><em> </em><em>a</em><em> </em><em>and</em><em> </em><em>b</em><em> </em><em>are</em><em> </em><em>even</em><em> </em>

return 2 * gcd(a/2, b/2)

elif((a%2 !=0) and (b%2==0)):

<em>#checks</em><em> </em><em>if</em><em> </em><em>a</em><em> </em><em>is</em><em> </em><em>odd</em><em> </em><em>and</em><em> </em><em>B</em><em> </em><em>is</em><em> </em><em>even</em><em> </em>

return gcd(a, b/2)

else :

return gcd(a, b-a)

<em>#since</em><em> </em><em>it's</em><em> </em><em>a</em><em> </em><em>recursive</em><em> </em><em>function</em><em>,</em><em> </em><em>it</em><em> </em><em>recalls</em><em> </em><em>the function</em><em> </em><em>with </em><em>new</em><em> </em><em>parameters</em><em> </em><em>until</em><em> </em><em>a</em><em> </em><em>certain</em><em> </em><em>condition</em><em> </em><em>is</em><em> </em><em>satisfied</em><em> </em>

print(gcd(124, 244))

print()

<em>#leaves</em><em> </em><em>a</em><em> </em><em>space</em><em> </em><em>after</em><em> </em><em>the</em><em> </em><em>first</em><em> </em><em>output</em><em> </em>

print(gcd(4424, 2111))

Learn more :brainly.com/question/25506437

You might be interested in
P(red)=3/12
Kitty [74]

Answer:

E) 9/12

Step-by-step explanation:

well first you need to know the number of non-red objects. There are 12 total so 12-3=9 non-red objects

9 out of 12 are non-red which is the exact same as the number of chances you have. 9/12

6 0
3 years ago
PLZ ANSWER THIS!!! I have no clue.
Advocard [28]
Density =mass/ volume
Volume= density/ mass

8 0
3 years ago
1. Gummy worms are $3.50 per pound
Alexxandr [17]
The constant of proportionality is 3.50 since gummy worms are sold at the same rate per pound.

3.50x, equation
3.50(2.5) = $8.75 for 2.5 pounds
3 0
3 years ago
35 POINTS!!! PLEASE HELP !!!!!!!!!!!!!!
lyudmila [28]

Answer:

The function is increasing from x = 0 to x = 1.

Step-by-step explanation:

A <u>function</u> is increasing when the <u>y-value increases</u> as the <u>x-value increases</u>.

A <u>function</u> is decreasing when the <u>y-value decreases</u> as the <u>x-value increases</u>.

From x = -2 to x = -1 the function is decreasing as the y-value decreases as the x-value increases:  

  • x-value -2 to -1 → increase
  • y-value 2 to 0 → decrease

From x = -1 to x = 0 the function is increasing as the y-value increases as the x-value increase:  

  • x-value -1 to 0 → increase
  • y-value 0 to 2 → increase

From x = 0 to x = 1 the function is increasing as the y-value increases as the x-value increase:  

  • x-value 0 to 1 → increase
  • y-value 2 to 8 → increase
7 0
1 year ago
(ii) Hence solve the following system of simultaneous equations:
gladu [14]

Answer:

Hi how are you doing today Jasmine

7 0
3 years ago
Other questions:
  • The first figure is dilated to form the second figure.
    14·2 answers
  • How do you solve these problems without numbers
    8·1 answer
  • What is acceleration produced by a force of 12 newton exerted on an object of mass 3kg​
    10·2 answers
  • A statistical test is conducted to see if there is evidence that the proportion of US citizens who can name the capital city of
    10·1 answer
  • 25, 34, 46, 37, 33, 42, 40, 37, 34, 49, 73, 46, 45, 45, 5. how many outliers do these data contain?
    8·2 answers
  • 1. Write the question y=-1/2x+3 in standard form.
    5·1 answer
  • A recipe calls for 2Start Fraction 3 over 4 End Fraction cups of sugar. How many fourths is that? A. 3 B. 8 C. 11 D. 14
    15·2 answers
  • Please please help me im really struggling
    5·1 answer
  • Review the two box and whisker plots:
    7·1 answer
  • 14. Solve the equation using the Zero Product Property
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!