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!
download android app

Popular C Examples









codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube