Arithmetic/Integer: Difference between revisions
Content added Content deleted
(→{{header|friendly interactive shell}}: Integer mathematics) |
(→{{header|REXX}}: re-wrote program to handle input from C.L. (or prompt), increased number of digits, made presentation easier, also shows X with Y --and-- Y with X results. -- ~~~~) |
||
Line 1,958: | Line 1,958: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
<lang rexx>/*REXX pgm gets 2 integers from the |
<lang rexx>/*REXX pgm gets 2 integers from the C.L. or via prompt, shows some opers*/ |
||
numeric digits 20 /*all numbers are rounded at ··· */ |
|||
/*··· the 20th significant digit.*/ |
|||
⚫ | |||
if y=='' then do /*nope, then prompt user for 'em.*/ |
|||
⚫ | |||
parse pull x y . |
|||
end |
|||
do 2 /*show A with B, then B with A.*/ |
|||
say /*show blank line for eyeballing.*/ |
|||
call show 'addition' , "+", x+y |
|||
⚫ | |||
call show 'subtraction' , "-", x-y |
|||
⚫ | |||
call show 'multiplication', "*", x*y |
|||
call show 'int division' , "%", x%y, ' [rounds down]' |
|||
call show 'real division' , "/", x/y |
|||
call show 'div remainder' , "//", x//y, ' [sign from 1st operand]' |
|||
call show 'power' , "**", x**y |
|||
parse value x y with y x /*swap the two values & do again.*/ |
|||
end /*2*/ |
|||
exit /*stick a fork in it, we're done.*/ |
|||
/*──────────────────────────────────SHOW subroutine─────────────────────*/ |
|||
say pad a " + " b yields a+b |
|||
show: parse arg what,oper,value,comment |
|||
say pad a " - " b yields a-b |
|||
say right(what,25)' ' x center(oper,4) y ' ───► ' value comment |
|||
say pad a " * " b yields a*b |
|||
return</lang> |
|||
say pad a " / " b yields a%b ' remainder (sign from the first operand): ' a//b |
|||
'''output''' when using the input of: <tt> 17 -4 </tt> |
|||
say pad a "** " b yields a**b</lang> |
|||
'''output''' |
|||
<pre> |
<pre> |
||
⚫ | |||
Enter two integer values (separated by blanks): |
|||
subtraction 17 - -4 ───► 21 |
|||
17 -4 ◄══════════════════════════════════════════ what the user entered. |
|||
multiplication 17 * -4 ───► -68 |
|||
17 |
int division 17 % -4 ───► -4 [rounds down] |
||
17 |
real division 17 / -4 ───► -4.25 |
||
17 |
div remainder 17 // -4 ───► 1 [sign from 1st operand] |
||
power 17 ** -4 ───► 0.000011973036721303624238 |
|||
⚫ | |||
addition -4 + 17 ───► 13 |
|||
subtraction -4 - 17 ───► -21 |
|||
multiplication -4 * 17 ───► -68 |
|||
int division -4 % 17 ───► 0 [rounds down] |
|||
real division -4 / 17 ───► -0.23529411764705882353 |
|||
div remainder -4 // 17 ───► -4 [sign from 1st operand] |
|||
power -4 ** 17 ───► -17179869184 |
|||
</pre> |
</pre> |
||