Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

l want the code Exercise 2: (Implementation of Euclid's algorithm) Euclid's algorithm is an ancient algorithm to find gcd(m,n), the greatest common divisor of two

l want the code
image text in transcribed
image text in transcribed
Exercise 2: (Implementation of Euclid's algorithm) Euclid's algorithm is an ancient algorithm to find gcd(m,n), the greatest common divisor of two nonnegative, not both zero integers m and n. Euclid's algorithm is based on repeated application of equality gcd(m,n)= gcd(n,mmodn) until the second number becomes 0. Example: gcd(24,9)=gcd(9,6)=gcd(6,3)=3 24mod9=69mod6=36mod3=0gcd(24,9)=gcd(9,6)=gcd(6,3)=3 Therefore, computing gcd (24,9) using Euclid's algorithm requires only three iterations while the algorithm in Exercise 1 requires 9(min(24,9)) iterations. When the numbers get bigger, the time efficiency of Euclid's algorithm gets more noticeable. Write a programming code for a function Euclid (m,n) that find the greatest common divisor using the Euclid's algorithm. You can use any language of Java/C ++/ Python/Octave. [CLO2.1, S1, 1 Mark] Euclid Algorithm : Step 1 If n=0, return m and stop; otherwise go to Step 2 . Step 2 Divide m by n and assign the value of the remainder to r. Step 3 Assign the yalue of n to m and the value of r to fo to Step 1. Write a programming code for a function Euclid (m,n) that find the greatest common divisor using the Euclid's algorithm. You can use any language of Java/C ++ Python/Octave. [CLO2.1, S1, 1 Mark] Euclid Algorithm : Step 1 If n=0, return m and stop; otherwise go to Step 2 . Step 2 Divide m by n and assign the value of the remainder to r. Step 3 Assign the value of n to m and the value of r to n. Go to Step 1 . while n=0 do rmmodn mn nr return m Write your programming code here

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 2 Lncs 8056

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013th Edition

3642401724, 978-3642401725

More Books

Students also viewed these Databases questions

Question

Why is stakeholder engagement important?

Answered: 1 week ago