Anonymous user
Arithmetic/Integer: Difference between revisions
m
{{out}}
(→{{header|Elixir}}: improvement) |
m ({{out}}) |
||
Line 3:
[[Category:Arithmetic]]
{{basic data operation}} [[Category:Simple]]
Get two integers from the user, and then output the sum, difference, product, integer quotient and remainder of those numbers
Don't include error handling.
For quotient, indicate how it rounds (e.g. towards 0, towards negative infinity, etc.).
For remainder, indicate whether its sign matches the sign of the first operand or of the second operand, if they are different.
Line 253 ⟶ 254:
printf(($"a UP b = a**b = a↑b = "gl$, a ** b))
)</lang>
{{out}}
<pre>
a+b = +468
Line 478 ⟶ 479:
}
}</lang>
{{out}}
<pre>5 + 3 = 8
5 - 3 = 2
Line 668 ⟶ 669:
</lang>
command: <i>cprun Arithmetic 12 23</i><br/>
{{out}}
<pre>
x + y > 35
Line 713 ⟶ 714:
</lang>
Command: Arithmetic.Go 12 23 ~ <br/>
{{out}}
<pre>
x + y > 35
Line 747 ⟶ 748:
a % b = -1
a ^^ b = -1048576</pre>
===Shorter Version===
Same output.
Line 1,036 ⟶ 1,038:
printf(1,"power(a,b) = %g\n", power(a,b))</lang>
{{out}}
<pre>a = 2
b = 3
Line 1,099 ⟶ 1,101:
} 2cleave</lang>
{{out}}
<pre>a=8
b=12
sum: 20
Line 1,113 ⟶ 1,114:
minimum: 8
gcd: 4
lcm: 24</
This example illustrates the use of cleave and apply combinators to alleviate the usage of shuffle words in a concatenative language.
bi@ applies a quotation to 2 inputs and 2cleave applies a sequence of quotations to 2 inputs.
=={{header|FALSE}}==
Line 1,207 ⟶ 1,209:
</lang>
{{out}}
<lang frink>
10 + 20 = 30
Line 1,289 ⟶ 1,291:
<lang groovy>arithmetic(5,3)</lang>
{{out}}
<pre> a + b = 5 + 3 = 8
a - b = 5 - 3 = 2
Line 1,486 ⟶ 1,488:
}
}</lang>
{{out}}
<pre>Enter an integer
-147
Line 1,839 ⟶ 1,841:
=={{header|ML/I}}==
ML/I will read two integers from 'standard input' or similar,
and then output the results to 'standard output' or similar.
<lang ML/I>MCSKIP "WITH" NL
Line 1,998 ⟶ 2,001:
return
</lang>
{{out}}
<pre style="height: 15ex; overflow:scroll;">
enter 2 integer values separated by blanks
Line 2,037 ⟶ 2,040:
</lang>
{{out}}
<pre>
Please type in an integer and press [enter]: 17
Line 2,079 ⟶ 2,081:
</lang>
Execute: Aritmint 10 23 <br>/
{{out}}
<pre>
a : 10
Line 2,133 ⟶ 2,135:
END Arithmetic.
</lang>
{{out}}
<pre>
Give two numbers: 12 23
Line 2,240 ⟶ 2,242:
<lang panda>a=3 b=7 func:_bbf__number_number_number =>f.name.<b> '(' a b ')' ' => ' f(a b) nl</lang>
{{out}}
<pre>atan2 ( 3 7 ) => 0.40489178628508343
divide ( 3 7 ) => 0.42857142857142855
Line 2,594 ⟶ 2,596:
arithmetic(12, 8)
arithmetic(input("Number 1: "), input("Number 2: "))</lang>
{{out}}
<pre>12 + 8 => 20
12 - 8 => 4
Line 2,633 ⟶ 2,635:
(arithmetic 8 12)
</lang>
{{out}}
<pre>
(+ 8 12) => 20
Line 2,713 ⟶ 2,715:
print ["Exponentiation:" x ** y]</lang>
{{out}}
<pre>Please type in an integer, and press [enter]: 17
Please enter another integer: -4
Line 2,939 ⟶ 2,940:
}</lang>
{{out}}
<pre>
** Integer a: 100
Line 3,138 ⟶ 3,139:
c=a%b
</lang>
{{out}}
<pre>
a=5
|