-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cmmdc and cmmmc
40 lines (35 loc) · 1.22 KB
/
Cmmdc and cmmmc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#Produced by/Realizat de Casiu George Valentin
"""
Sǎ se afişeze cel mai mare divizor comun si cle mai mic multiplu comun a doua numere./Display the greatest common divisor and the least common multiple of two numbers.
"""
def cmmdc(a,b):
while a!=b:
if a>b:
a=a-b
else:
b=b-a
return(a)
def cmmdcr(a,b):#the recursive version/varianta recursiva
if a==b: return a
elif a>b:return cmmdcr(a-b,b)
else: return cmmdcr(a,b-a)
def cmmmc(a,b):
c=a
d=b
while a!=b:
if a<b:
a+=c
else:
b+=d
return a
def citirenat(text):# natural number reading/citire numar natural
n=''
while not(n.isdecimal()): # if n is not decimal/daca n nu e zecimal
n = input(text)
n = n.strip(' +')# remove spaces and '+' from the beginning and end of number/elimina spatiile libere si '+' de la inceputul si sfarsitul numarului
return int(n)
# The main program/Programul principal
a=citirenat("Enter the first number/Introduceti primul numar:")
b=citirenat("Enter the second number/Introduceti al doilea numar:")
print("The gratest common divisor/Cmmdc=", cmmdc(a,b))
print("The least common multiple/Cmmmc=", cmmmc(a,b))