Skip to content

Instantly share code, notes, and snippets.

@rajvanshipradeep15
Created November 4, 2016 07:10
Show Gist options
  • Save rajvanshipradeep15/f1ba4fb9ea38f6f8ddf21b37c7dedbb0 to your computer and use it in GitHub Desktop.
Save rajvanshipradeep15/f1ba4fb9ea38f6f8ddf21b37c7dedbb0 to your computer and use it in GitHub Desktop.
get Remainder and quotient for a given numerator and denominator
<?php
// your code goes heref
function getRemainder( $n, $d )
{
for($i =1; $i<$n; $i++) {
if( $n == $d*$i) {
$remainder = 0;
$quotient = $i;
break;
} elseif( $n > $d * $i) {
continue;
} elseif( $n < $d * $i ) {
$remainder = $n - ($d * ($i-1));
$quotient = $i - 1;
break;
}
}
echo "remainder: " . $remainder . "\n";
echo "quotient: " . $quotient . "\n";
}
getRemainder(10,10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment