0% found this document useful (0 votes)
33 views2 pages

Euclidean Algorithm: Shruthi Srinivasan 2017PIS5174

The document discusses the Euclidean algorithm for finding the greatest common divisor (GCD) of two numbers. It defines the GCD as the largest integer that divides both numbers. The algorithm works by recursively finding the GCD of the remainder of one number divided by the other, until the remainder is zero. An example application of the algorithm finds that the GCD of 35 and 8 is 1. Source code in Python is provided to implement the Euclidean algorithm.

Uploaded by

albus_ron
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views2 pages

Euclidean Algorithm: Shruthi Srinivasan 2017PIS5174

The document discusses the Euclidean algorithm for finding the greatest common divisor (GCD) of two numbers. It defines the GCD as the largest integer that divides both numbers. The algorithm works by recursively finding the GCD of the remainder of one number divided by the other, until the remainder is zero. An example application of the algorithm finds that the GCD of 35 and 8 is 1. Source code in Python is provided to implement the Euclidean algorithm.

Uploaded by

albus_ron
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Euclidean Algorithm

Shruthi Srinivasan
2017PIS5174

The Euclidean Algorithm is a method used to compute GCD of two natural


numbers. It is named after the Greek Mathematician Euclid. GCD (Greatest
Common Divisior) of two numbers A and B is the largest integer that divides
both the numbers.

The function states that:


(
a(x) = 0 b(x) = 0
GCD(a(x), b(x)) =
GCD(b(x), a(x) mod b(x)) otherwise

Algorithm :

GCD(a(x),b(x))

1. If b(x) =0 then GCD = a(x), return GCD and stop

2. If b(x) != 0 then divide a(x) by b(x) and let r be the remainder. If r =0


then GCD =b(x) , return GCD and stop
3. Replace a(x) by b(x) and b(x) by r and return to step 2

Example :

To find GCD of 35 and 8

GCD(35, 8) = GCD(8, 3) (1)


= GCD(3, 2) (2)
= GCD(3, 2) (3)
= GCD(2, 1) (4)
= GCD(1, 0) (5)
=1 (6)

Source Code in Python:

1
d e f gcd ( a , b ) :
p r i n t C a l l i n g gcd(%d,%d ) %(a , b )
i f ( b==0) :
p r i n t \nGCD o f %d and %d i s %d %(num1 ,
num2 , a )
else :
gcd ( b , a%b )
print

p r i n t ( Program t o f i n d GCD o f two numbers u s i n g E u c l i d e a n


s a l g o r i t h m \n )
print

num1 = i n p u t ( Enter t h e f i r s t number )


num2 = i n p u t ( Enter t h e s e c o n d number )
gcd (num1 , num2)
Output:

You might also like