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
Hello!! Plz ans with explanation.. Plz!! I need it ASAP!!! PLZ TYSM<br>Faaast!!
jonny [76]

Answer:

1/4

1/2

3/4

Step-by-step explanation:

<u>Given</u><u>:</u>

Types of colors in the spinner

Yellow 1

Red 2

Blue 1

Total:4

Successful outcome of Yellow:1

Successful outcome of Red:2

Successful outcome of Blue:1

<u>Required</u><u>:</u>

Probability of the

  • blue sector
  • red sector
  • not on yellow sector

<u>Formula</u><u>:</u>

Probability= successful outcome ÷ possible outcome

<u>Solution</u><u> </u>

  • Blue sector

Probability=1 ÷ 4

  • Red sector

Probability= 2÷4

  • not on yellow sector

Probability= 3÷4

Hope this helps ;) ❤❤❤

7 0
3 years ago
Which series of transformations shows that heptagon A is congruent to heptagon B?
Arte-miy333 [17]

Answer: Reflect heptagon A over the y-axis, rotate it 90° counterclockwise about the point (4, 3), and translate it 8 units down.

Step-by-step explanation:

3 0
3 years ago
Identify an equation in point-slope form for the line perpendicular to y=-1/2x+11 that passes through (4,-8).
lana66690 [7]

Answer:

A. y+8=2(x-4)

Step-by-step explanation:

A line perpendicular to y=-1/2x+11 would have slope +2, which is the negative reciprocal of -1/2.

Starting with the slope-intercept form of the equation of a straight line, find the y-intercept based upon this new line's passing through (4, -8):

y = mx + b becomes  -8 = 2(4) + b.  Then b = -16, and the desired new line is

y = 2x - 16.  

Eliminate answer choices B and C, because 1/2 is not the correct slope.

Choice A is correct.  Note that the result of subbing 4 for x and -8 for y into A:  y + 8 = 2(x - 4) is a true equation:  -8 + 8 = 2(4 - 4)

Also note that y + 8 = 2(x - 4) can be written in slope-intercept form:

y = -8 + 2x - 8, or y = 2x - 16 (same as obtained earlier)

7 0
4 years ago
BRAINLIEST FOR RIGHT ANSWER PLZ
Karolina [17]

The surface area of this figure is __<u>310</u>__ square centimetres.

6 0
3 years ago
How can numbers be expressed ordered and compared for a third grader
Anarel [89]
Line all the numbers in a column and compared where the numbers are not the same numbers
7 0
4 years ago
Other questions:
  • A glass bottle of fruit punch contains 3.5 L how many 200 mL servings are in a container
    5·1 answer
  • 60% of what equals 27
    7·2 answers
  • Simplify each expression involving signed numbers.
    15·1 answer
  • Ava takes guitar lessons. The lessons cost $90 each month. She has 4 lessons per
    6·1 answer
  • Help me with algebra homework.
    11·1 answer
  • Evaluate the composition of logarithms. (Write answer as a number)
    13·1 answer
  • Which of the following mixed numbers is equivalent to 12.1 6 ?
    14·2 answers
  • The equation 4s + 3d = 33 is used to determine the number of sandwiches, s, and drinks, d, that can be purchased with $33. If yo
    7·1 answer
  • GIVING BRAINLIEST HURRY
    11·2 answers
  • Please help, due tomorrow. Will give brainlist
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!