C Program to Find GCD of two Numbers


GCD of two integers is the largest integer that can exactly divide both numbers without remainder.

  1. #include <stdio.h>
  2. int main()
  3. {
  4. int no1, no2, i, gcd;
  5. printf("Enter two integers: ");
  6. scanf("%d %d", &no1, &no2);
  7. for(i=1; i <= no1 && i <= no2; ++i)
  8. {
  9. // Checks if i is factor of both integers
  10. if(no1%i==0 && no2%i==0)
  11. gcd = i;
  12. }
  13. printf("G.C.D of %d and %d is %d", no1, no2, gcd);
  14. return 0;
  15. }

Output

Output!