Created
November 4, 2016 07:10
-
-
Save rajvanshipradeep15/f1ba4fb9ea38f6f8ddf21b37c7dedbb0 to your computer and use it in GitHub Desktop.
get Remainder and quotient for a given numerator and denominator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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