- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

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

# gcd() function Python

Greatest common divisor or gcd is a mathematical expression to find the highest number which can divide both the numbers whose gcd has to be found with the resulting remainder as zero. It has many mathematical applications. Python has a inbuilt gcd function in the math module which can be used for this purpose.

## gcd()

It accepts two integers as parameter and returns the integer which is the gcd value.

### Syntax

Syntax: gcd(x,y) Where x and y are positive integers.

### Example of gcd()

In the below example we print the result of gcd of a pair of integers.

import math print ("GCD of 75 and 30 is ",math.gcd(75, 30)) print ("GCD of 0 and 12 is ",math.gcd(0, 12)) print ("GCD of 0 and 0 is ",math.gcd(0, 0)) print ("GCD of -24 and -18 is ",math.gcd(-24, -18))

### Output

Running the above code gives us the following result −

GCD of 75 and 30 is 15 GCD of 0 and 12 is 12 GCD of 0 and 0 is 0 GCD of -24 and -18 is 6

- Related Questions & Answers
- C program to find GCD of numbers using recursive function
- How to Find HCF or GCD using Python?
- C program to find GCD of numbers using non-recursive function
- Find original numbers from gcd() every pair in Python
- Grand Central Dispatch (GCD)
- Minimum removals from array to make GCD Greater in Python
- Program to compute gcd of two numbers recursively in Python
- Find GCD of two numbers
- C++ Program to Find GCD
- Python Program for GCD of more than two (or array) numbers
- GCD of more than two (or array) numbers in Python Program
- Euclidean Algorithm for calculating GCD in JavaScript
- Finding gcd of two strings in JavaScript
- Intersection() function Python
- Python zip() Function

Advertisements