# C program to find GCD of two numbers using while loop

## Program to find the GCD of  two numbers using while loop

GCD  is the Greatest Common Divisor among two integer numbers. The GCD is also known as HCF (Highest Common Factor) or GCF (Greatest Common Factor).  For Example : The Greatest Common Divisor (GCD) of 20 and 15 is 5. The below given C program will find the Greatest Common Divisor (GCD) of given any two integer numbers (Positive or Negative) using while loop. Kindly check out the program to find the Greatest Common Divisor (GCD) of given any two integer numbers.

### Program to find GCD of two numbers

#include <stdio.h>
int main(){
int num1, num2, nm1, nm2;
printf("Enter two integers: ");
scanf("%d %d", &nm1, &nm2);
num1 = abs(nm1);
num2 = abs(nm2);
while(num1!=num2)
{
if(num1 > num2)
num1 =num1 - num2;
else
num2 = num2 - num1;
}
printf("The Greatest Common Divisor of %d and %d is %d",nm1, nm2, num1);
return 0;
}

Sample Output:

Enter two integers:  20   15
The Greatest Common Divisor of  20  and  15  is  5