Posted on November 3rd, 2010 by Jans
Posted on October 5th, 2010 by Jans
Posted on March 19th, 2010 by Jans
Posted on February 2nd, 2010 by Jans
Recently one of my friend asked me to write a function in PHP for multiplying two numbers without * or / operators. Also we should not use any loops. I got the following solution.
function mul($a,$b)
{
if($b==1){return $a;}
return $a+mul($a,$b-1);
}
echo mul(5,6);
One more solution which i found is as follows. But is is using the division(/) operator.
function mul($a,$b)
{
return $a/(1/$b);
}
echo mul(15,3);
Filed under: PHP | No Comments »
Posted on January 12th, 2010 by Jans