gcd() function in python by R4R Team

GCD-
-stands for greatest common divisor.

Example-
numbers are 12 and 8
gcd will 4

numbers are 13 and 17
gcd will 1

program-

import math
print("Enter first number")
a=int(input())
print("Enter Second number")
b=int(input())
print("Greatest common divisor is "+str(math.gcd(a,b)))
print(type(math.gcd(a,b)))


output -

Enter first number
12
Enter Second number
8
Greatest common divisor is 4
<'class 'int'>

Enter first number
13
Enter Second number
17
Greatest common divisor is 1
<'class 'int'>


-In this program, we take 2 input of integer number and find the gcd(greatest common divisor) which is same as hcf, here we import the math library because gcd() is a build-in function which is defined in math library.

Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!