Instantly share code, notes, and snippets.

Embed
What would you like to do?
Math Operators: sum, difference, product, quotient, remainder, increment, decrement, greater then comparison
<?php
echo "Enter 1st number:";
$num1 = trim(fgets(STDIN));
echo "Enter 2nd number:";
$num2 = trim(fgets(STDIN));
$sum = $num1 + $num2; //sum
echo ("Sum: "."\n".$sum."\n \n");
$dif = $num1 - $num2; //difference
echo ("Difference: "."\n".$dif."\n \n");
$pro = $num1 * $num2; //product
echo ("Product: "."\n".$pro."\n \n");
$quo = $num1 / $num2; //quotient
echo ("Quotient: "."\n".$quo."\n \n");
$rem = $num1 % $num2; //remainder
echo ("Remainder: "."\n".$rem."\n \n");
$inc = ++$num1; //increment 1st number
echo ("Increment 1st No: "."\n".$inc."\n \n");
$dec = --$num2; //decrement 2nd number
echo ("Decrement 2nd No: "."\n".$dec."\n \n");
if($num1 > $num2){ //1st no > 2nd no?
$num3 = "1st No. is greater then the 2nd No.";
echo ($num3."\n");
exit;
}
else {
$num3 = "1st No. is NOT greater then the 2nd No.";
echo ($num3."\n");
exit;
}
exit;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment