Description
The G.C.D. ( Greatest Common Divisor ) or H.C.F. ( Highest Common Factor ) of two numbers is the largest positive integer that perfectly divides the two given numbers.
For Example:
The G.C.D. of 10 and 14 is 2
Method 1
a = int(input("Enter the number 1 : "))
b = int(input("Enter the number 2 : "))
l = []
l1 = []
gcd = 1
for i in range(1, a + 1):
if a % i == 0:
l.append(i)
for j in range(1, b + 1):
if b % j == 0:
l1.append(j)
for item in l:
for i in l1:
if item == i:
gcd = gcd * item
print("GCD : ", gcd)
Method 2
a = int(input("Enter the number 1 : "))
b = int(input("Enter the number 2 : "))
gcd = 0
r = 1
while(r > 0):
if b > a:
r = b % a
gcd = a
a = r
else:
r = a % b
gcd = b
b = r
print(gcd)
Method 3
a = 45
b = 66
t = 1
while(t <= a and t <= b):
if a%t == 0 and b%t==0:
gcd = t
t=t+1
print("GCD : ", gcd)
Recommended Posts
Given Number is EVEN Or ODD in Python Programming Language
Write a program to check that given number is Even or Odd in Python Programming language.
Diet Exercise Management System in Python
In this tutorial we write a management system which maintain the diet and exercise of the user.
Find the greatest number given three number by user in python programming
Write a program to check that given three number is by user in Python Programming language.
Calculate the area of circle in Python Programming
In this tutorial, we will learn all about the circle ( area, circumference ) with all types of method. Inbuild Methods, function, simple so on.
leap year in python
The year which has 366 days is called a leap year. This additional day is added in february which makes it 29 days long.
Fibonacci Series | Fibonacci Sequence in Python
Fibonacci numbers ( series ) is a set of numbers that start with 1 or 0 followed by a 1 proceeds on the rule that each number.