GoCoding.org

Program for Basic Euclidean Algorithm using Python

by | Jul 14, 2021 | Python Programs

Introduction

The task is to find the greatest common divisor (GCD) of two given numbers.

Program for Basic Euclidean Algorithm using Python

Program

def find(num1, num2): 
    if num1 == 0 :
        return num2 
   
    return find(num2%num1, num1)
num1 = int(input("Enter the first number:"))
num2 = int(input("Enter the second number:"))
print("Output: gcd({0},{1}) = {2} ".format(num1,num2,find(num1, num2)))

Output

Program for Basic Euclidean Algorithm using Python Output

Explanation

In Basic Euclidean Algorithm, we divide the smaller number and check if remainder is equalled to zero. The number is returned when remainder is found to be zero.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.