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
Henrietta is mixing paint for an art project. She uses 2 cups of red paint for every 3 cups of yellow paint for each batch. If s
bezimeni [28]
2/3=6/x
2x=6*3
2x=18
x=18/2
x=9
5 0
3 years ago
The angle of elevation of a tower, 45 m high from a ball on the ground 52 degree (a) how far is the ball from the foot of the to
blsea [12.9K]

The distance of the ball from the foot of the tower is : 35.18m

The ball would be moved 57.2m away from the foot of the tower for the Angle of elevation to be halved.

<h3>What is angle of elevation?</h3>

Angle of elevation is the angle formed between the horizontal and the  line of view from the vertical.

Analysis:

The height of the tower and the distance of the ball from the foot of the tower form a right angle triangle.

so we use trigonometry.

a) let distance of the ball from foot of tower be x.

  so that, tan 52 = 45/x

  x = 45/tan52

  x = 45/1.279 = 35.18m

b) let the distance of the ball in the new position from the foot of the tower be y.

if the angle of elevation is halved, then new angle is 52/2 = 26°

 tan 26 = 45/y

y = 45/tan26 = 45/0.487 = 92.4m

distance moved from old position to new position = 92.4 - 35.18 = 57.2m

In conclusion, the distance of the ball from the foot of the tower and the distance the ball should move to make its elevation 26° are 35.18m and 57.2m respectively.

Learn more about angle of elevation: brainly.com/question/88158

#SPJ1

4 0
2 years ago
I need helpp !!!!!!!!!!!
natta225 [31]

Answer:

In descending order, 1, 4, 3

4 0
3 years ago
Duffy completed a 50-meter dash in 36 seconds. That was 90 percent of the time it took Paul to complete it. What was Paul's time
Law Incorporation [45]

Answer: C

Step-by-step explanation: Cross multiply.

36/90 = x/100

3600/90 = 40

8 0
3 years ago
Help it’s my last question
Digiron [165]

Answer:

alr so basically what you want to do is multiply the numbers to get the answer

Step-by-step explanation:

6 0
2 years ago
Other questions:
  • A teacher already had a certain Number of canned goods for the food drive each day of the food drive the class plans to ring in
    15·1 answer
  • Write an expression and<br>then solve for x.<br>149​
    13·1 answer
  • 864 multiple by two third ?
    11·1 answer
  • A right rectangular prism has a length of 2 1/2 feet, a width of 3 feet,and a height of 1 1/2 feet. Unit cubes with side lengths
    13·1 answer
  • Write in slope intercept form an equation of the line that passes through the point (g,h) with slope j
    14·1 answer
  • (05.05)
    10·1 answer
  • Triangle RST has vertices R(-3,2), S(0,-5),and T(4,5).When translated R’ has coordinates (4, 1). Find the coordinates of S’ and
    8·1 answer
  • Help meeeeeeeeeeeee​
    14·2 answers
  • Garth had unexpected expenses this month and didn’t have enough in his saving account to pay the rent of $600. He went to Loansh
    13·1 answer
  • Draw a number line that includes both positive and negative integers from +5 to -5.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!