Write a program to find GCD of two numbers
The GCD or HCF (Highest Common Factor) of two integers is the greatest integer that
divides both the integers with remainder equals to zero. This can be illustrated by Euclid’s
remainder Algorithm which states that GCD of two numbers say x and y i.e.
GCD(x, y) = x if y is 0
= GCD(y, x%y) otherwise
The program which implements the previous logic is as follows:
#include int GCD(int,int); void main() { int a,b,gcd; printf(“Enter two numbers”); scanf(“%d%d”,&a,&b); gcd=GCD(a,b); printf(“GCD of %d and %d is %d”,a,b,gcd); } int GCD(int x, int y) { if(y==0) return x; else return GCD(y,x%y); }
Output: Enter two numbers 21 35 GCD of 21 and 35 is 7