insanepenguin Posted May 25, 2010 Share Posted May 25, 2010 function getGCF($a, $b){ if($b == 0){ return $a; } else { return getGCF($b, $a % $b); } } Can someone explain how the 'returnGCF' function works, I know for example the greatest common factor of 6, 2 is 2 because 2 is the greatest number to go in to 6 and itself. I'm just a bit confused about the modulus % part: 2, 6 % 2 = 2 any explanations to help a newbie welcome! Quote Link to comment https://forums.phpfreaks.com/topic/202814-greatest-common-factor/ Share on other sites More sharing options...
Mchl Posted May 25, 2010 Share Posted May 25, 2010 6 % 2 = 0 actually. Modulus will give you a remainder from division of two numbers. For example, when youdivide 10 by 3, you can 'fit' three 3s into 10, and there will be 1 left. Hence 10 % 3 = 1 Quote Link to comment https://forums.phpfreaks.com/topic/202814-greatest-common-factor/#findComment-1062921 Share on other sites More sharing options...
MadTechie Posted May 25, 2010 Share Posted May 25, 2010 modulus gives you the remainder of a division for example 100 % 24 = 4 24 goes into 100, 4 times but then has 4 remaining 100 - 24 = 76 76 - 24 = 52 52 - 24 = 28 28 - 24 = 4 Quote Link to comment https://forums.phpfreaks.com/topic/202814-greatest-common-factor/#findComment-1062925 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.