C Programming Code Examples C > If Else and Switch Case Code Examples GCD Using while loop and if...else Statement GCD Using while loop and if...else Statement The HCF or GCD of two integers is the largest integer that can exactly divide both numbers (without a remainder). #include <stdio.h> int main() { int j1, j2; printf("Enter two positive integers: "); scanf("%d %d",&j1,&j2); while(j1!=j2) { if(j1 > j2) j1 -= j2; else j2 -= j1; } printf("GCD = %d",j1); return 0; }