COMPUTER SCIENCE PYTHON AND C++
Monday, June 29, 2020
Write a Recursive Python program to find the greatest common divisor (gcd) of two integers.
def
Recurgcd
(
a
,
b
)
:
low
=
min
(
a
,
b
)
high
=
max
(
a
,
b
)
if
low
==
0
:
return
high
elif
low
==
1
:
return
1
else
:
return
Recurgcd
(
low
,
high
%
low
)
print
(
Recurgcd
(
12
,
14
)
)
Recurgcd
(
12
,
14
)=
return
Recurgcd
(
low
,
high
%
low
)
Recurgcd
(
12
,
14
)=
return
Recurgcd
(
12,2)
)
Recurgcd
(
12
,
14
)=
return
Recurgcd
(
return
Recurgcd
(
2,0
))
Recurgcd
(
12
,
14
)=
return
Recurgcd
(
return
2
)
Recurgcd
(
12
,
14
)=
return
2
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment