Jump to content

Greatest common factor


insanepenguin

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/202814-greatest-common-factor/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.