w3resource
php Programming Exercies

PHP Exercises: Calculate the mod of two given integers without using any inbuilt modulus operator

PHP: Exercise-40 with Solution

Write a PHP program to calculate the mod of two given integers without using any inbuilt modulus operator.

Sample Solution: -

PHP Code:

<?php
function without_mod($m, $n)
{
   $divides=(int)($m/$n);
   return $m-$n*$divides;
}
echo without_mod(13, 2)."\n";
echo without_mod(81, 3)."\n";
?>

Sample Output:

1                                                           
0        

PHP Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a PHP program to get the size of a file.
Next: Write a PHP program to print out the multiplication table upto 6*6.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming