Given two numbers the task is to find the Greatest Common Factor or Highest Common Factor.
Example: 36 and 60 have a GCD of 12 since it is the only maximum number by which 36 and 60 both are divisible.
C
#include <stdio.h>
int main()
{
int n1=0,n2=0,min=0,gcd=0;
printf("Enter first number: ");
scanf("%d",&n1);
printf("Enter second number: ");
scanf("%d",&n2);
min=(n1<=n2)?n1:n2;
for(int i=1;i<=min;i++)
{
if(n1%i==0&&n2%i==0)
{
gcd=i;
}
}
printf("GCD of %d and %d is: %d",n1,n2,gcd);
return 0;
}C