in this article, Python is based on recursive and non recursive algorithms for finding the greatest common divisor and the least common multiple of the two numbers. Share to everyone for your reference, specific as follows:

the maximum common divisor and the minimum common multiple of the concept of everyone is very familiar with, here is not much said, today this is because when the problem encountered, so it is written down as a record, also hope to help others, the next is the code

! /usr/bin/env PY Thon #coding:utf-8 from fractions import GCD not recursively implement def gcd_test_one (a, b): if a. Print'Number is wrong!! def gcd_test_two recursive def gcd_test_two (a, b): if a> b: a. Print gcd_test_one (6,24) print gcd_test_one (0,24) print '- -- - --- print gcd_test_two (12,24) print. - -- 'print gcd_test_three (12,24) print gcd_test_three (12,8) 

results are as follows:

. ----------------------------------------------------

PS: here is a new online tool for you to refer to:

more readers interested in Python related content can view the site theme: "Python mathematical computing skills summary ", < a disabilities "data structure and algorithm tutorial < "/a>", "Python function uses skill summary ", "Python string manipulation skills summary ", "

you may be interested in the article:

This paper fixed link: | Script Home | +Copy Link

Article reprint please specify:Python based on recursive and non recursive algorithm for finding the greatest common divisor and least common multiple of two numbers | Script Home

You may also be interested in these articles!