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.

The quotient rounds towards 0 if both inputs are integers or towards negative infinity if either input is floating point. The sign of the remainder is always the same as the sign of the first parameter (dividend).

Exponentiation's note: With nawk or gawk, $1 ** $2 acts like $1 ^ $2. With mawk, $1 ** $2 is a syntax error. Nawk allows **, but its manual page only has ^. Gawk's manual warns, "The POSIX standard only specifies the use of `^' for exponentiation. For maximum portability, do not use the `**' operator."

procedure Test( a, b )?"a+b", a + b?"a-b", a - b?"a*b", a * b// The quotient isn't integer, so we use the Int() function, which truncates it downward.?"a/b",Int( a / b )// Remainder:?"a%b", a % b// Exponentiation is also a base arithmetic operation?"a**b", a ** breturn

* *> Note: The various ADD/SUBTRACT/etc. statements can be* *> replaced with COMPUTE statements, which allow those* *> operations to be defined similarly to other languages,* *> e.g. COMPUTE Result = A + B

ADD A TO B GIVING ResultDISPLAY"A + B = " Result

SUBTRACT B FROM A GIVING ResultDISPLAY"A - B = " Result

MULTIPLY A BY B GIVING ResultDISPLAY"A * B = " Result

* *> Division here truncates towards zero. DIVIDE can take a* *> ROUNDED clause, which will round the result to the nearest* *> integer.DIVIDE A BY B GIVING ResultDISPLAY"A / B = " Result

/* NOTE:Division by zero defaults to generating a zero result (0), rather than reporting a “divide by zero” error. This avoids invalid or unexpected data aborting a long job. This default behavior can be changed*/

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.

Different host systems have different native signed division behavior. ANS Forth defines two primitive double-precision signed division operations, from which the implementation may choose the most natural to implement the basic divide operations ( / , /mod , mod , */ ). This is partly due to differing specifications in the two previous standards, Forth-79 and Forth-83.

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:

procedure Test( a, b )?"a+b", a + b?"a-b", a - b?"a*b", a * b// The quotient isn't integer, so we use the Int() function, which truncates it downward.?"a/b",Int( a / b )// Remainder:?"a%b", a % b// Exponentiation is also a base arithmetic operation?"a**b", a ** breturn

A=5; B=-4; A + B =1 A - B =9 A * B =-20 A / B =-1.25truncate A / B =-1round next A / B =-1round down A / B =-2round up A / B =-1remainder of A / B =1A to the power of B = 16E-4 A to the power of B = 16E-4

This image is a VI Snippet, an executable image of LabVIEW code. The LabVIEW version is shown on the top-right hand corner. You can download it, then drag-and-drop it onto the LabVIEW block diagram from a file browser, and it will appear as runnable, editable code.

Note that raising to a power can display very large integers without going to approximate power-of-ten notation.

input"Enter the first integer: "; firstinput"Enter the second integer: "; second

print"The sum is " ; first + secondprint"The difference is " ; first -secondprint"The product is " ; first *secondif second <>0thenprint"The integer quotient is " ; int( first /second); " (rounds towards 0)"elseprint"Division by zero not allowed."print"The remainder is " ; first MOD second; " (sign matches first operand)"print"The first raised to the power of the second is " ; first ^second

Each infix operator also has a prefix synonym (sum, difference, product, quotient). Sum and product can also have arity greater than two when used in parentheses (sum 1 2 3). Infix operators in general have high precedence; you may need to enclose their arguments in parentheses to obtain the correct expression.

Note: M[UMPS] has an operator called "modulo".
When both operands are positive numbers, "modulo" has a result that looks a lot like "remainder";
however, there is an important difference.

To better understand the intricacies of "modulo" and how it is
different from "remainder", see Donald Knuth's definition (Volume 1 of the "big books"), or
find out the beauty of cyclic algebra as formulated by Niels Henrik Abel (August 5, 1802 – April 6, 1829).

All Arithmetic in NSIS is handled by the IntOp instruction. It is beyond the scope of this task to implement user input (a fairly involved task), so I will be providing hard-coded values simulating the user input, with the intention of later adding the user-input piece.

Integer division with \ rounds to . There also exists the \/ round-to-nearest (ties to ) operator. Ordinary division / does not round but returns rationals if given integers with a non-integral quotient.

Note that div doesn't always do integer division; it performs the operation "most appropriate to the
operand types". Synopsis 3 guarantees that div "on built-in integer types is equivalent to taking the floor of a real division". If you want integer division with other types, say floor($a/$b).

Numbers are automatically converted to accomodate for the result. This means not only that Int32 will be expanded to Int64 but also that a non-integer quotient will cause the result to be of a floating-point type.

The remainder has the sign of the first operand.

No exponentiation operator exists, but can be worked around with the .NET BCL:

Notes: In Python3 raw_input() will be renamed to input() (the old input() built-in will go away, though one could use eval(input()) to emulate the old ... and ill-advised ... behavior). Also a better program would wrap the attempted int() conversions in a try: ... except ValueError:... construct such as:

(In general it's good practice to perform parsing of all input in exception handling blocks. This is especially true of interactive user input, but also applies to data read from configuration and other files, and marshaled from other processes via any IPC mechanism).

Python also has the procedure divmod that returns both quotient and remainder. eg

; REBOL evaluates infix expressions from left to right. There are no; precedence rules -- whatever is first gets evaluated. Therefore when; performing this comparison, I put parens around the first term; ("sign? a") of the expression so that the value of /a/ isn't; compared to the sign of /b/. To make up for it, notice that I don't; have to use a specific return keyword. The final value in the; function is returned automatically.

/*REXX pgm gets 2 integers from the C.L. or via prompt, shows some opers*/numericdigits20/*all numbers are rounded at ··· *//*··· the 20th significant digit.*/parsearg x y ./*maybe the integers are on C.L.?*/if y==''thendo/*nope, then prompt user for 'em.*/say"─────Enter two integer values (separated by blanks):"parsepull x y .enddo2/*show A with B, then B with A.*/say/*show blank line for eyeballing.*/

Since Tcl doesn't really know about the "type" of a variable, the "expr" command is used to declare whatever follows as an "expression". This means there is no such thing as "integer arithmetic" and hence the kludge with int([gets stdin]).

Often, these operations would be performed in a different way from what is shown here. For example, to increase the variable "x" by the value of the variable "y", one would write

incr x $y

Also, it's important to surround the arguments to the expr in braces, especially when any of the parts of the expression are not literal constants. Discussion of this is on The Tcler's Wiki.

Notes: Using the ` (backtick operators, also available in most Bourne shells via the $(...) syntax) allows us to keep the results on their labels in the most efficient and portable way. The spaces around the operators in the expr command line arguments are required and the shell requires us to quote or escape the * character has shown, to prevent any possible "globbing" --- filename expansion of the * as a wildcard character.

Note: spaces inside the $((...)) are optional and not required; the $((...)) can be inside or outside the double quotes, but the `...` expressions from the previous example can also be inside or outside the double quotes.