Arithmetic/Integer: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 315:
remainder :resultat : +1
</PRE>
 
=={{header|ABAP}}==
<lang ABAP>report zz_arithmetic no standard page heading.
Line 465 ⟶ 466:
WriteF('A mod B =\d\n', Mod(a,b))
ENDPROC</lang>
 
=={{header|APL}}==
<lang apl>∇res ← integer_arithmetic; l; r
Line 994 ⟶ 996:
printf("a/b = %d\n", a/b); /* truncates towards 0 (in C99) */
printf("a%%b = %d\n", a%b); /* same sign as first operand (in C99) */
return 0;
}</lang>
 
=={{header|C++}}==
<lang cpp>#include <iostream>
 
int main()
{
int a, b;
std::cin >> a >> b;
std::cout << "a+b = " << a+b << "\n";
std::cout << "a-b = " << a-b << "\n";
std::cout << "a*b = " << a*b << "\n";
std::cout << "a/b = " << a/b << ", remainder " << a%b << "\n";
return 0;
}</lang>
Line 1,036 ⟶ 1,024:
5 % 3 = 2
5 to the power of 3 = 125</pre>
 
=={{header|C++}}==
<lang cpp>#include <iostream>
 
int main()
{
int a, b;
std::cin >> a >> b;
std::cout << "a+b = " << a+b << "\n";
std::cout << "a-b = " << a-b << "\n";
std::cout << "a*b = " << a*b << "\n";
std::cout << "a/b = " << a/b << ", remainder " << a%b << "\n";
return 0;
}</lang>
 
=={{header|Chef}}==
Line 1,272 ⟶ 1,274:
x MOD y > 12
</pre>
 
=={{header|D}}==
<lang d>import std.stdio, std.string, std.conv;
Line 1,327 ⟶ 1,330:
[mod: ]P la lb % p sz [sign matches first operand]sz
[pow: ]P la lb ^ p sz</lang>
 
=={{header|DCL}}==
<lang DCL>$ inquire a "Enter first number"
Line 1,727 ⟶ 1,731:
<lang excel>
=$A1^$B1
</lang>
 
=={{header|F_Sharp|F#}}==
As F# is a functional language, we can easily create a list of pairs of the string name of a function and the function itself to iterate over printing the operation and applying the function to obtain the result:
<lang fsharp>
do
let a, b = int Sys.argv.[1], int Sys.argv.[2]
for str, f in ["+", ( + ); "-", ( - ); "*", ( * ); "/", ( / ); "%", ( % )] do
printf "%d %s %d = %d\n" a str b (f a b)
</lang>
For example, the output with the arguments 4 and 3 is:
<lang fsharp>
4 + 3 = 7
4 - 3 = 1
4 * 3 = 12
4 / 3 = 1
4 % 3 = 1
</lang>
 
Line 1,843 ⟶ 1,864:
-12 ^ 7 = -35831808
</pre>
 
=={{header|F_Sharp|F#}}==
As F# is a functional language, we can easily create a list of pairs of the string name of a function and the function itself to iterate over printing the operation and applying the function to obtain the result:
<lang fsharp>
do
let a, b = int Sys.argv.[1], int Sys.argv.[2]
for str, f in ["+", ( + ); "-", ( - ); "*", ( * ); "/", ( / ); "%", ( % )] do
printf "%d %s %d = %d\n" a str b (f a b)
</lang>
For example, the output with the arguments 4 and 3 is:
<lang fsharp>
4 + 3 = 7
4 - 3 = 1
4 * 3 = 12
4 / 3 = 1
4 % 3 = 1
</lang>
 
 
=={{header|friendly interactive shell}}==
Line 1,896 ⟶ 1,899:
10 ^ 20 = 100000000000000000000
</lang>
 
 
=={{header|FutureBasic}}==
Line 2,534 ⟶ 2,536:
{{VI snippet}}<br/>
[[File:LabVIEW_Arithmetic_Integer.png]]
 
 
 
=={{header|Lasso}}==
Line 3,086:
And 0&2 = 0
Or 0!2 = 1</lang>
 
 
=={{header|Nanoquery}}==
Line 3,112 ⟶ 3,111:
Remainder: 5
Power: 15625</pre>
 
 
=={{header|Nemerle}}==
Line 3,319 ⟶ 3,317:
x MOD y > 12
</pre>
 
=={{header|Objeck}}==
<lang objeck>bundle Default {
Line 3,502 ⟶ 3,501:
]
System.showInfo}</lang>
 
=={{header|PARI/GP}}==
Integer division with <code>\</code> rounds to <math>-\infty</math>. There also exists the <code>\/</code> round-to-nearest (ties to <math>+\infty</math>) operator. Ordinary division <code>/</code> does not round but returns rationals if given integers with a non-integral quotient.
<lang parigp>arith(a,b)={
print(a+b);
print(a-b);
print(a*b);
print(a\b);
print(a%b);
print(a^b);
};</lang>
 
=={{header|Panda}}==
Line 3,531 ⟶ 3,519:
plus ( 3 7 ) => 10
pow ( 3 7 ) => 2187</pre>
 
=={{header|PARI/GP}}==
Integer division with <code>\</code> rounds to <math>-\infty</math>. There also exists the <code>\/</code> round-to-nearest (ties to <math>+\infty</math>) operator. Ordinary division <code>/</code> does not round but returns rationals if given integers with a non-integral quotient.
<lang parigp>arith(a,b)={
print(a+b);
print(a-b);
print(a*b);
print(a\b);
print(a%b);
print(a^b);
};</lang>
 
=={{header|Pascal}}==
Line 3,559 ⟶ 3,558:
"exponent: ", $a ** $b, "\n"
;</lang>
 
=={{header|Perl 6}}==
{{works with|Rakudo|2015.09}}
<lang perl6>my Int $a = get.floor;
my Int $b = get.floor;
 
say 'sum: ', $a + $b;
say 'difference: ', $a - $b;
say 'product: ', $a * $b;
say 'integer quotient: ', $a div $b;
say 'remainder: ', $a % $b;
say 'exponentiation: ', $a**$b;</lang>
 
Note that <code>div</code> doesn't always do integer division; it performs the operation "most appropriate to the
operand types". [http://perlcabal.org/syn/S03.html#line_729 Synopsis 3] guarantees that <code>div</code> "on built-in integer types is equivalent to taking the floor of a real division". If you want integer division with other types, say <code>floor($a/$b)</code>.
 
=={{header|Phix}}==
Line 3,643 ⟶ 3,627:
(prinl "Modulus " (% A B)) # Sign of the first operand
(prinl "Power " (** A B)) )</lang>
 
=={{header|Piet}}==
[[File:PietArithmaticInteger.png]]<br>
Line 3,718 ⟶ 3,703:
x y exp =
} def</lang>
 
=={{header|PowerShell}}==
<lang powershell>$a = [int] (Read-Host First Number)
Line 3,734 ⟶ 3,720:
No exponentiation operator exists, but can be worked around with the .NET BCL:
<lang powershell>[Math]::Pow($a, $b)</lang>
 
=={{header|ProDOS}}==
<lang ProDOS>IGNORELINE Note: This example includes the math module.
Line 3,949 ⟶ 3,936:
(lcm 8 12) => 24
</pre>
 
=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2015.09}}
<lang perl6>my Int $a = get.floor;
my Int $b = get.floor;
 
say 'sum: ', $a + $b;
say 'difference: ', $a - $b;
say 'product: ', $a * $b;
say 'integer quotient: ', $a div $b;
say 'remainder: ', $a % $b;
say 'exponentiation: ', $a**$b;</lang>
 
Note that <code>div</code> doesn't always do integer division; it performs the operation "most appropriate to the
operand types". [http://perlcabal.org/syn/S03.html#line_729 Synopsis 3] guarantees that <code>div</code> "on built-in integer types is equivalent to taking the floor of a real division". If you want integer division with other types, say <code>floor($a/$b)</code>.
 
=={{header|Raven}}==
Line 4,523 ⟶ 4,526:
print ("~a = " ^ Int.toString (~a) ^ "\n") (* unary negation, unusual notation compared to other languages *)
end</lang>
 
=={{header|Swift}}==
<lang swift>
Line 4,898 ⟶ 4,902:
println("x%y = ",x % y); // remainder; matches sign of first operand when operands' signs differ
println("x.divr(y) = ",x.divr(y)); // (x/y,remainder); sign as above</lang>
 
=={{header|zonnon}}==
<lang zonnon>
Line 4,923 ⟶ 4,928:
remainder: 2
</pre>
 
=={{header|ZX Spectrum Basic}}==
<lang zxbasic>5 LET a=5: LET b=3
10,333

edits