0

Are GCD and HCF same or different? Also what is its code?

6th Oct 2016, 9:22 AM
Parth Krishna
Parth Krishna - avatar
2 Respuestas
0
GCD and HCF are practically the same thing. If you want to find the GCD between two numbers, here is a function i once made for that purpose. It works for two numbers though, but if you get the idea you can extend it for multiple numbers: def gcd(a, b): a = float(a); b=float(b) if a >b: smallest = b else: smallest = a counter = smallest; i = 0 while i < counter: i += 1 if (a%smallest==0) and (b%smallest==0) factor = smallest break smallest -= 1 return factor
6th Oct 2016, 8:30 PM
Fhatuwani Luvhengo
Fhatuwani Luvhengo - avatar
0
yes they are same findGcd(int a, int b){ return (a == 0) ? b : findGcd(b%a, a); }
29th Jun 2017, 10:20 PM
Pradeep Pankaj
Pradeep Pankaj - avatar