viernes, 1 de junio de 2018

GCF and LCM


GCF and LCM, automated


What follows is a working Python.3.7 program.  It must be installed to get results.

#gcf and lcm
def gcf(a,b):
    if a%b==0:
        return b
    else:
        return gcf(b,a%b)

def lcm(a,b):
    m = int()
    m = a*b//gcf(a,b)
    return m
print("Type gcf(a,b), for a,b positive integers")
print("Type lcm(a,b), for a,b positive integers")


Example:

 gcf(358, 456)
2
 lcm(358,456)
81624
 
Note: a % b means the residue for division between a and b
Example: 7 % 4 =3.

No hay comentarios:

Publicar un comentario