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:
 
=={{header|REXX}}==
<lang rexx>/*REXX pgm gets 2 integers from the consoleC.L. andor displaysvia variousprompt, resultsshows some opers*/
pad=left('',10)numeric digits 20 /*usedall fornumbers indentingare therounded output.at ··· */
yields=' ───► ' /*use this to show "yields". /*··· the 20th significant digit.*/
say parse arg x y . /*addmaybe athe blankintegers lineare toon the outputC.L.?*/
if y=='' then do /*nope, then prompt user for 'em.*/
say "Enter─────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 . parse value x y with y x /*or,swap couldthe use:two values & do PULL A B again. */
end /*2*/
 
say exit /*addstick a blankfork linein toit, thewe're outputdone.*/
/*──────────────────────────────────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>
addition 17 ** + -4 ───► 0.000011973036713
Enter two integer values (separated by blanks):
subtraction 17 - -4 ───► 21
17 -4 ◄══════════════════════════════════════════ what the user entered.
multiplication 17 * -4 ───► -68
int division 17 +% -4 ───► -4 [rounds 13down]
real division 17 -/ -4 ───► 21-4.25
div remainder 17 *// -4 ───► 1 -68 [sign from 1st operand]
17 / -4 ───► power -4 17 remainder (sign** from the-4 first operand):───► 10.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>