Arithmetic/Integer: Difference between revisions

Content added Content deleted
(→‎{{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 console and displays various results*/
<lang rexx>/*REXX pgm gets 2 integers from the C.L. or via prompt, shows some opers*/
pad=left('',10) /*used for indenting the output. */
numeric digits 20 /*all numbers are rounded at ··· */
yields=' ───► ' /*use this to show "yields". */
/*··· the 20th significant digit.*/
parse arg x y . /*maybe the integers are on C.L.?*/
if y=='' then do /*nope, then prompt user for 'em.*/
say "─────Enter two integer values (separated by blanks):"
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


parse pull a b . /*or, could use: PULL A B . */
parse value x y with y x /*swap the two values & do again.*/
end /*2*/

say /*add a blank line to the output.*/
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>
addition 17 + -4 ───► 13
Enter two integer values (separated by blanks):
subtraction 17 - -4 ───► 21
17 -4 ◄══════════════════════════════════════════ what the user entered.
multiplication 17 * -4 ───► -68
17 + -4 ───► 13
int division 17 % -4 ───► -4 [rounds down]
17 - -4 ───► 21
real division 17 / -4 ───► -4.25
17 * -4 ───► -68
div remainder 17 // -4 ───► 1 [sign from 1st operand]
17 / -4 ───► -4 remainder (sign from the first operand): 1
power 17 ** -4 ───► 0.000011973036721303624238

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>
</pre>