Arithmetic/Integer: Difference between revisions

→‎{{header|REXX}}: changed the program (for validating the input), add/changed comments and whitespace.
(→‎{{header|REXX}}: changed the program (for validating the input), add/changed comments and whitespace.)
Line 2,621:
 
=={{header|REXX}}==
<lang rexx>/*REXX pgm gets 2 integers from the C.,L. or via prompt,; shows some opersoperations.*/
numeric digits 20 /*all numbers#s are roundedround at ···20th significant dig.*/
parse arg x y . /*maybe the integers are on the C.L. /*··· 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.*/
 
do while \datatype(x,'W') | \datatype(y,'W') /*both X and Y must be ints.*/
call show 'addition' , "+", x+y
say "─────Enter two integer values (separated by blanks):"
call show 'subtraction' , "-", x-y
parse argpull x y . /*maybeaccept thetwo integersitems arefrom oncommand Cline.L.? */
call show 'multiplication', "*", x*y
end /*2while ··· */
call show 'int division' , "%", x%y, ' [rounds down]'
say /*show blank[↓] line forperform eyeballingthis DO loop twice. */
call show 'real division' , "/", x/y
if y=='' then do j=1 for 2 /*nopeshow A oper B, then prompt userB oper for 'emA.*/
call show 'div remainder' , "//", x//y, ' [sign from 1st operand]'
call show 'poweraddition' , "**+", x**+y
call show 'additionsubtraction' , "+-", x+-y
call show 'subtractionmultiplication' , "-*", x-*y
call show 'int division' , "%", x%y, ' [rounds down]'
call show 'multiplicationreal division' , "*/", x*/y
call show 'divdivision remainder' , "//", x//y, ' [sign from 1st operand]'
call show 'real divisionpower' , "/**", x/**y
 
parse value x y with y x /*swap the two values &and doperform again.*/
if j==1 then say copies('═', 79) /*display a fence after the 1st round. */
end /*2*/
end /*j*/
exit /*stick a fork in it, we're done.*/
exit do 2 /*showstick a Afork within Bit, then we're Ball withdone. A.*/
/*──────────────────────────────────SHOW subroutine─────────────────────*/
/*────────────────────────────────────────────────────────────────────────────*/
show: parse arg what,oper,value,comment
show: parse arg c,o,#,?; say right(whatc,25)' ' x center(opero,4) y ' ───► ' # ?; value commentreturn</lang>
'''output''' when using the input of: &nbsp; <tt> 17 &nbsp; -4 </tt>
return</lang>
'''output''' when using the input of: <tt> 17 -4 </tt>
<pre>
addition 174 + -417 ───► -13
subtraction 174 - -417 ───► 21
multiplication 174 * -417 ───► -68
int division 174 % -417 ───► -40 [rounds down]
real division 174 / -417 ───► -40.2523529411764705882353
divdivision remainder 174 // -417 ───► 14 [sign from 1st operand]
power 174 ** -417 ───► 05.0000119730367213036242388207660913467407227E-11
═══════════════════════════════════════════════════════════════════════════════
 
addition -417 + 174 ───► -13
subtraction -417 - 174 ───► -21
multiplication -417 * 174 ───► -68
int division -417 % 174 ───► 0-4 [rounds down]
real division -417 / 174 ───► -04.2352941176470588235325
divdivision remainder -417 // 174 ───► -41 [sign from 1st operand]
power -417 ** 174 ───► -1717986918483521
</pre>