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:
=={{header|REXX}}==
<lang rexx>/*REXX pgm gets 2 integers from the
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
▲say /*add a blank line to the output.*/
call show 'subtraction' , "-", x-y
▲say "Enter two integer values (separated by blanks):"
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
end /*2*/
/*──────────────────────────────────SHOW subroutine─────────────────────*/
show: parse arg what,oper,value,comment
say right(what,25)' ' x center(oper,4) y ' ───► ' value comment
return</lang>
'''output''' when using the input of: <tt> 17 -4 </tt>
<pre>
subtraction 17 - -4 ───► 21
multiplication 17 * -4 ───► -68
int division 17
real division 17
div remainder 17
▲ 17 ** -4 ───► 0.0000119730367
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>
|