Professional Documents
Culture Documents
.in
ac
1
k.
© Malay K. Das; mkdas@ iitk.ac.in
iit
@
as
Recall the Pseudocode for computing the greatest common divisor (gcd) of two non-
kd
of
output: gcd of
where
while
if
swap the values of
We are now ready to code
the pseudocode in python
end while
We will use the jupyter lab tool within the anaconda (or miniconda) environment
2
Improving the pseudocode by creating a function
input: non-negative, at least one nonzero, integers function takes few values as
output: gcd of inputs and delivers one value
as output
function gcd(m,n)
function may be called from
while
other functions
if
swap the values of function improves modularity
of the program. Modern,
end while large programs rely heavily
.in
return on modularity
end function gcd(m,n)
ac
We will now code the pseudocode in python and call it from the main program
3
k.
© Malay K. Das; mkdas@ iitk.ac.in
iit
@
as
input: non-negative, at least one nonzero, integers we wish to run the else block
until the top if block is
output: gcd of satisfied (m = n is reached)
m
function gcd(m,n)
if this is achieved by calling the
return function gcd from the same
else function
if
swap the values of such idea, in programming, is
called recursion
endif
we can now implement the
endif
same in python
return gcd(m,n)
end function gcd(m,n)
4
Summary
Discussed three different ways of writing pseudocode and python program
for finding gcd
Exercise
.in
Thank You
ac
5
k.
© Malay K. Das; mkdas@ iitk.ac.in
iit
@
as
kd
m