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]
2 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]2 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
3. What is the slope of the line passing through (15,-5) and (3, -8)?
Andrej [43]
M= -8 - -5/ 3 - 15= -8+5/3-15= -3/-12 = 3/12 = 1/4 


The slope is 1/4. 
The slope formula is m=y2-y1/x2-x1. I plugged in -8=y2, -5=y1, 3=x2, and 15=x1. Then I solved it.
6 0
3 years ago
Read 2 more answers
HELP ASAP Calculate the residuals for your scatterplot in step 2d.
postnew [5]

The residuals of the linear regression equation are -1.36, 0.32, 0.01, 0.62, 0.17, -0.24, 0.89, 0.09, 0.18 and -0.7

<h3>How to determine the residuals?</h3>

The regression equation is given as:

y = 0.141x + 0.842

Next, we calculate the predicted values (y) at the corresponding x values.

So, we have:

y = 0.141 * 13.8 + 0.842 = 2.78

y = 0.141 * 18 + 0.842 = 3.38

y = 0.141 * 16.7 + 0.842 = 3.20

y = 0.141 * 18 + 0.842 = 3.38

y = 0.141 * 0.7 + 0.842 = 0.94

y = 0.141 * 21.9 + 0.842 = 3.93

y = 0.141 * 15.5 + 0.842 = 3.03

y = 0.141 * 9.2 + 0.842 = 2.14

y = 0.141 * 19.5 + 0.842 = 3.59

y = 0.141 * 16.7 + 0.842 = 3.20

The residuals are then calculated using:

Residual = Actual value - Predicted value

So, we have:

Residual = 1.42 - 2.78 = -1.36

Residual = 3.7 - 3.38 = 0.32

Residual = 3.21 - 3.20 = 0.01

Residual = 4 - 3.38 = 0.62

Residual = 1.11 - 0.94 = 0.17

Residual = 3.69 - 3.93 = -0.24

Residual = 3.92 - 3.03 = 0.89

Residual = 2.23 - 2.14 = 0.09

Residual = 3.77 - 3.59 = 0.18

Residual = 2.5 - 3.20 = -0.7

Hence, the residuals of the linear regression equation are -1.36, 0.32, 0.01, 0.62, 0.17, -0.24, 0.89, 0.09, 0.18 and -0.7

Read more about residuals at:

brainly.com/question/16180255

#SPJ1

6 0
1 year ago
Please help me and others that will stumble on this problem.
lutik1710 [3]

Answer:

A (0,0)

Step-by-step explanation:

When a function intersects the y-axis then the point of intersection is called y-intercept of the function,

Also, for y-intercept x = 0.

That is, if f(x) is the function then its y-intercept is (0, f(0) )

By the given table for x = 0, f(x) = 0

Hence, the y-intercept of the given function is (0,0),

Option A is correct.

5 0
2 years ago
Solve 11 2/5 = q - 4 2/7 + 2 1/7
RideAnS [48]
I turn the mixed numbers into decimals before doing anything else.
11 2/5----> 57/5----> 11.4
4 2/7----> 30/7----> 4.29
2 1/7----> 15/7----> 2.14

11.4=q-4.29+2.14
11.4=q-2.15
13.55= q

13.55 converted to a fraction is 13 11⁄20
q=13 11⁄20
6 0
3 years ago
Is 70 written in standard form or word form explain
Tanzania [10]
The standard form of this number is 7 * 10^1. The word form of this number is seventy.
8 0
3 years ago
Read 2 more answers
Other questions:
  • What is the value of x?<br> 45°<br> m<br> (2x-5)<br> n
    6·1 answer
  • 780000 is the successor of what
    9·1 answer
  • If f(x)=6x-7 and g(x)= -3x-8 what is f(g(6))
    11·1 answer
  • Matt is standing on top of a cliff 305 feet above a lake.the measurement of the angle of depression to a boat on the lake is 42°
    12·1 answer
  • Trigonometric functions
    10·1 answer
  • Emily works at a local restaurant. She made $200 in tips last night. She shared 15 percent of her tips with the crew that cleans
    10·2 answers
  • Select the correct answer.
    6·1 answer
  • 17more than a number is 85​
    14·2 answers
  • A town of 3200, grows at a rate of 25% every year. Find the size of the city in 10 years.
    5·2 answers
  • Name an angle vertical to
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!