C Program to Implement The Greatest Common Divisor Or Highest Common Factor.
GCD is also called the HCF(Highest Common Factor). Suppose we want to calculate gcd or hcf of 16 and 24, here are the steps that are being implemented in c program for gcd: 1. Find the factors of 16. i.e 2*2*2*=16 and factors of 24 is 2*2*2*3=24. 2. Find all the common factors of 16 and 24. And multiply all the common factors or same factors, i.e 2*2*2 = 8. Hence gcd or hcf of 24 and 16 is 8.

ALGORITHM:-

step 1 : Start
step 2 : Enter Two number to calculate GCD
step 3 : Calculate the Greatest Common Divisor
step 4 : Stop Execution



PROGRAM CODE:-

#include<stdio.h>
#include<conio.h>
void hcf(int a,int h)
{
    int temp;
    while(1)
    {
         temp = a%h;
         if(temp==0)
         return h;
         a = h;
         h = temp;
    }
}
int main()
{
     int c,d,e;
     printf("enter values to find gcd\n"); 
     scanf("%d%d",&c,&d);
     e=hcf(c,d);
     printf("\ngcd of %d and %d is %d.",c,d,e);
     getch();
}

OUTPUT:-

Enter Two number to calculate Greatest common divisor
16
24


GCD of 16 and 24 is: - 8.


C Program To Calculate the Greatest Common factor (GCD)
How to calculate GCD using c
Greatest Common Disisor using C.