Arithmetic/Integer: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
Line 526: | Line 526: | ||
<code>(mod a b)</code> and <code>(rem a b)</code> return numbers equal to the secondary values of <code>(floor a b)</code> and <code>(truncate a b)</code>, respectively. |
<code>(mod a b)</code> and <code>(rem a b)</code> return numbers equal to the secondary values of <code>(floor a b)</code> and <code>(truncate a b)</code>, respectively. |
||
=={{header|Component Pascal}}== |
|||
Works with Gardens Point Component Pascal |
|||
<lang oberon2> |
|||
MODULE Arithmetic; |
|||
IMPORT CPmain,Console,RTS; |
|||
VAR |
|||
x,y : INTEGER; |
|||
arg : ARRAY 128 OF CHAR; |
|||
status : BOOLEAN; |
|||
PROCEDURE Error(IN str : ARRAY OF CHAR); |
|||
BEGIN |
|||
Console.WriteString(str);Console.WriteLn; |
|||
HALT(1) |
|||
END Error; |
|||
BEGIN |
|||
IF CPmain.ArgNumber() < 2 THEN Error("Give me two integers!") END; |
|||
CPmain.GetArg(0,arg); RTS.StrToInt(arg,x,status); |
|||
IF ~status THEN Error("Can't convert '"+arg+"' to Integer") END; |
|||
CPmain.GetArg(1,arg); RTS.StrToInt(arg,y,status); |
|||
IF ~status THEN Error("Can't convert '"+arg+"' to Integer") END; |
|||
Console.WriteString("x + y >");Console.WriteInt(x + y,6);Console.WriteLn; |
|||
Console.WriteString("x - y >");Console.WriteInt(x - y,6);Console.WriteLn; |
|||
Console.WriteString("x * y >");Console.WriteInt(x * y,6);Console.WriteLn; |
|||
Console.WriteString("x / y >");Console.WriteInt(x DIV y,6);Console.WriteLn; |
|||
Console.WriteString("x MOD y >");Console.WriteInt(x MOD y,6);Console.WriteLn; |
|||
END Arithmetic. |
|||
</lang> |
|||
command: <i>cprun Arithmetic 12 23</i><br/> |
|||
output: |
|||
<pre> |
|||
x + y > 35 |
|||
x - y > -11 |
|||
x * y > 276 |
|||
x / y > 0 |
|||
x MOD y > 12 |
|||
</pre> |
|||
=={{header|D}}== |
=={{header|D}}== |
||
<lang d>import std.stdio, std.string, std.conv; |
<lang d>import std.stdio, std.string, std.conv; |