Q3. Write a code to find GCD of two numbers

GCD :- GCD stands for Greatest Common Divisor, GCD of two numbers is the largest number that can exactly divide both numbers. It is also called as HCF.

For Example :-
Input = 25 and 10
Output = 5 is the GCD.
As we can see that 5 divides both 25 and 10 and we don’t have any larger number that divides both the numbers therefore, the GCD of 25 and 10 is 5.

Algorithm for GCD

START
1. Input 2 Numbers A and B and declare variable GCD which holds the result.
2. Run Loop i from 1 to i <= A and i <=B
Check if A & B are completely divisible by i or not if yes then
Assign GCD = i
Loop End
3. Output GCD
STOP

Code for GCD

Output

GCD of 25 and 10 is 5

Recommended Programs
Program to find factorial of a number
Program to count number of digits in a number