M Instructions gcd.py + + >_ Terminal + E The greatest common divisor of two positive integers. A and B. is the largest

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

M Instructions gcd.py + + >_ Terminal + E The greatest common divisor of two positive integers. A and B. is the largest

Post by answerhappygod »

M Instructions Gcd Py Terminal E The Greatest Common Divisor Of Two Positive Integers A And B Is The Largest 1
M Instructions Gcd Py Terminal E The Greatest Common Divisor Of Two Positive Integers A And B Is The Largest 1 (85.22 KiB) Viewed 107 times
M Instructions gcd.py + + >_ Terminal + E The greatest common divisor of two positive integers. A and B. is the largest number that can be evenly divided into both of them. Euclid's algorithm can be used to find the greatest common divisor (GCD) of two positive integers. You can use this algorithm in the following manner: 1. Compute the remainder of dividing the larger 1 A = int(input("Enter A: ")) A 2 B = int(input("Enter B: ")) 3 4 #finding the larger and smaller number 5 large number = max(A,B) 6 smaller_number = min(A,B) 7 8 #repeating the steps 1 and 2 that are given in the question 9 #ntill smaller_number equals zero 10 while smaller_number!=0: 11 #1) Computing the reminder of dividing larger number by smaller number 12 reminder = large_number%smaller_number 13 #2) Replacing the larger number with the smaller number and 14 # smaller_number with reminder 15 large_number = smaller_number 16 smaller_number = reminder 17 18 #printing the GCD of A and B 19 print("GCD of", A, ",",B," is", large_number) 20 number by the smaller number. 2. Replace the larger number with the smaller number and the smaller number with the remainder. 3. Repeat this process until the smaller number is zero. The larger number at this point is the GCD of A and B. Write a program that lets the user enter two integers and then prints each step in the process of using the Euclidean algorithm to find their GCD. An example of the program input and output is shown below:

An example of the program input and output is shown below: Enter the smaller number: 5 Enter the larger number: 15 The greatest common divisor is 5 Grading When you have completed your program, click the Submit button to record your score.

Tasks gcd.py + >_ Terminal Enter A: | Program produces correct output given input 6.67 out of 10.00 2 out of 3 checks passed. Review the results below for more details. . Checks 1 A = int(input("Enter A: ")) 2 B = int(input("Enter B: ")) 3 3 4 #finding the larger and smaller number 5 large number = max(A,B) 6 smaller_number = min(A,B) 7 8 #repeating the steps 1 and 2 that are given in the question 9 #ntill smaller_number equals zero 10 while smaller_number!=0: 11 #1) Computing the reminder of dividing larger number by smaller number 12 reminder = large_number%smaller_number 13 #2) Replacing the larger number with the smaller number and 14 # smaller_number with reminder 15 large_number = smaller_number 16 smaller_number = reminder 17 18 #printing the GCD of A and B 19 print("GCD of",,",",B," is", large_number) 20 > Test Case • Complete Test for 5 and 15 > Test Case • Complete Test for 30 and 90 > Test Case Incomplete Test for 162 and 8571
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply