Friday, 7 December 2018

Finding the GCD of two numbers


Finding the GCD of two numbers

Algorithm for finding GCD of two numbers:
Step1 : Start
Step2 : Declare three variables m,n and r
Step3 : Read numbers into m and n whose GCD is to be found.
Step4 : If one of the numbers is zero then goto end.
Step5 : Find out the reminder (m % n) and store it in r
Step6 : If r is zero then print n which is the GCD of m and n and goto end.
Step7 : If r is not zero then assign value of n to m and assign value of r to n
Step8 : Repeat steps 5 to 7 until r is zero.
Step9 : Stop

Flow Chart for finding GCD of two numbers:


No comments:

Post a Comment