fork download
  1. #include <stdio.h>
  2.  
  3. int min(int a,int b){
  4. if(a<b) return a;
  5. else return b;
  6. }
  7. int gcd(int a,int b){
  8. int hcf;
  9. for(int i=1;i<=min(a,b);i++){
  10. if(a%i==0 && b%i==0){
  11. hcf=i;
  12. }
  13. }
  14. return hcf;
  15. }
  16.  
  17.  
  18. int main(void) {
  19. int a;
  20. printf("Enter 1st number: \n");
  21. scanf("%d",&a);
  22. int b;
  23. printf("Enter the 2nd number: ");
  24. scanf("%d",&b);
  25.  
  26. int hcf=gcd(a,b);
  27. printf("The HCF/GCD of %d and %d is %d",a,b,hcf);
  28.  
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0.01s 5292KB
stdin
70
100
stdout
Enter 1st number: 
Enter the 2nd number: The HCF/GCD of 70 and 100 is 10