To Find GCD of two Numbers


SUBMITTED BY: kaushal1981

DATE: Feb. 21, 2017, 9:20 p.m.

FORMAT: Text only

SIZE: 364 Bytes

HITS: 823

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

comments powered by Disqus