In this we are going to see a basic program to calculate GCD using classes in Python Programming Language.
class gcd:
def __init__(self):
self.a = 0
self.b = 0
def find(self):
print("Enter the value of a and b: ", end='')
self.a, self.b = map(int, input().split())
while self.a != self.b:
if self.a > self.b:
self.a = self.a - self.b
if self.b > self.a:
self.b = self.b - self.a
print("The GCD is: ", end='')
print(self.a, end='')
obj1 = gcd()
obj1.find()
#Coded by SAAHIL
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP