Calculate H.C.F using while loop - C Program

C program to calculate the H.C.F of two numbers.

Solution:

H.C.F is Highest Common Factor. It is also known as G.C.D i.e Greatest Common Divisor. For example, 15 and 36 are two numbers.
15= 5*3
36=6*6 = 3*2*3*2.
The greatest common factor of 15 and 36 is 3.

#include<stdio.h>
int main()
{
      int a,b,i=1,x;
      printf("Enter Two Numbers To Find H.C.F\n");
      printf("---------------------------\n");
      printf("Enter First Number  : ");
      scanf("%d", &a);
      printf("\nEnter Second Number : ");
      scanf("%d",&b);
      while(i<=a || i<=b)
      {
            if(a%i==0 && b%i==0)
                  x=i;
            i++;
      }
      printf("---------------------------\n");
      printf("H.C.F of %d & %d : %d",a,b,x);
      return 0;
}


Output:

calculate hcf