Anonymous user
Arithmetic/Integer: Difference between revisions
Updated D code to D2
m (→{{header|PowerShell}}: method capitalization. PowerShell is case-insensitive, but it looks nicer :-)) |
(Updated D code to D2) |
||
Line 402:
=={{header|D}}==
<lang d>import std.stdio, std.string, std.conv;
void main() {
int a = to!int(readln().strip());
writefln("a - b = ", a-b);▼
writeln("a % b = ", a % b);
writeln("a ^^ b = ", a ^^ b);
}</lang>
Output:
<pre>a = -16, b = 5
a + b = -11
a - b = -21
a * b = -80
a / b = -3
a % b = -1
a ^^ b = -1048576</pre>
Alternative version (same output):
<lang d>import std.stdio, std.string, std.conv, std.typetuple;
void main() {
int a = to!int(readln().strip());
int b = to!int(readln().strip());
writeln("a = ", a, ", b = ", b);
foreach (op; TypeTuple!("+", "-", "*", "/", "%", "^^"))
mixin(`writeln("a ` ~ op ~ ` b = ", a` ~ op ~ `b);`);
}</lang>
|