Arithmetic/Integer: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added/changed comments and whitespace, changed indentations.) |
|||
Line 2,827: | Line 2,827: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
All operators automatically produce integers (up to 20 decimal digits in the program below), |
All operators automatically produce integers (up to 20 decimal digits in the program below), |
||
<br>or numbers in exponential format when necessary. |
|||
<lang rexx>/*REXX |
<lang rexx>/*REXX program gets two integers from the C,L. or via a prompt; shows some operations.*/ |
||
numeric digits 20 /*#s are round at 20th significant dig.*/ |
|||
numeric digits 20 /*#s are round at 20th significant dig.*/ |
|||
parse arg x y . /*maybe the integers are on the C.L. */ |
|||
do while \datatype(x,'W') | \datatype(y,'W') |
do while \datatype(x,'W') | \datatype(y,'W') /*both X and Y must be integers. */ |
||
say "─────Enter two integer values (separated by blanks):" |
say "─────Enter two integer values (separated by blanks):" |
||
parse pull x y . /*accept two |
parse pull x y . /*accept two thingys from command line.*/ |
||
end /*while |
end /*while*/ |
||
/* [↓] perform this DO loop twice. */ |
/* [↓] perform this DO loop twice. */ |
||
do j=1 for 2 /*show A oper B, then B oper A.*/ |
do j=1 for 2 /*show A oper B, then B oper A.*/ |
||
call show 'addition' , "+", x+y |
call show 'addition' , "+", x+y |
||
call show 'subtraction' , "-", x-y |
call show 'subtraction' , "-", x-y |
||
Line 2,846: | Line 2,847: | ||
call show 'power' , "**", x**y |
call show 'power' , "**", x**y |
||
parse value x y with y x /*swap the two values and perform again*/ |
parse value x y with y x /*swap the two values and perform again*/ |
||
if j==1 then say copies('═', 79) /*display a fence after the 1st round. */ |
if j==1 then say copies('═', 79) /*display a fence after the 1st round. */ |
||
end /*j*/ |
end /*j*/ |
||
exit /*stick a fork in it, we're all done. */ |
exit /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
/*────────────────────────────────────────────────────────────────────────────*/ |
|||
show: parse arg c,o,#,?; say right(c,25)' ' x center(o,4) y |
show: parse arg c,o,#,?; say right(c,25)' ' x center(o,4) y " ───► " # ?; return</lang> |
||
'''output''' when using the input of: <tt> 17 -4 </tt> |
'''output''' when using the input of: <tt> 17 -4 </tt> |
||
<pre> |
<pre> |