- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Python Program for Basic Euclidean algorithms

In this article, we will learn about the solution to the problem statement given below.

**Problem statement**− Given two numbers we need to calculate gcd of those two numbers and display them.

GCD Greatest Common Divisor of two numbers is the largest number that can divide both of them. Here we follow the euclidean approach to compute the gcd i.e. to repeatedly divide the numbers and stop when the remainder becomes zero.

Now let’s observe the solution in the implementation below −

## Example

# euclid algorithm for calculation of greatest common divisor def gcd(a, b): if a == 0 : return b return gcd(b%a, a) a = 11 b = 15 print("gcd of ", a , "&" , b, " is = ", gcd(a, b))

## Output

gcd of 11 & 15 is = 1

All the variables are declared in the local scope and their references are seen in the figure above.

## Conclusion

In this article, we have learned about how we can make a Python Program for Basic Euclidean algorithms.

- Related Articles
- C Program for Basic Euclidean algorithms?
- Python Program for Extended Euclidean algorithms
- C Program for Extended Euclidean algorithms?
- Basic calculator program using Python program
- Basic calculator program using Python
- Euclidean Algorithm for calculating GCD in JavaScript
- C++ Program to Implement Extended Euclidean Algorithm
- Finding Euclidean distance using Scikit-Learn in Python
- What is basic syntax of Python for Loops?
- Introduction to Algorithms for Mathematical Problems
- What are the basic scoping rules for python variables?
- Calculating Euclidean distance using SciPy
- How can we do the basic print formatting for Python numbers?
- Basic Python Programming Challenges
- Basic Operators in Python

Advertisements