C program to convert GCD of the given 2 numbers

In this program we will calculate GCD (Greatest Common Divisor) or HCF (Highest Common Factor).

C program to convert GCD of the given 2 numbers

#include <stdio.h>
int main()
{
  int n1, n2;
  printf("Enter two positive integers: ");
  scanf("%d %d", &n1, &n2);
  while (n1 != n2)
  {
    if (n1 > n2)
      n1 -= n2;
    else
      n2 -= n1;
  }
  printf("GCD = %d", n1);
  return 0;
}

Output

Enter two positive integers: 36 96
GCD = 12

Read: C program to find LCM of the given 3 numbers


If You Like This Page Then Make Sure To Follow Us on Facebook, G News and Subscribe Our YouTube Channel. We will provide you updates daily.
Shares
facebook sharing button Share
twitter sharing button Tweet
whatsapp sharing button Share
telegram sharing button Share
pinterest sharing button Pin

Leave a Comment