How to resolve the algorithm Arithmetic/Integer step by step in the Nemerle programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Arithmetic/Integer step by step in the Nemerle programming language
Table of Contents
Problem Statement
Get two integers from the user, and then (for those two integers), display their:
Don't include error handling. For quotient, indicate how it rounds (e.g. towards zero, 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.
Bonus: Include an example of the integer divmod
operator. For example: as in #Haskell, #Python and #ALGOL 68
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Arithmetic/Integer step by step in the Nemerle programming language
Source code in the nemerle programming language
using System;
class Program
{
static Main(args : array[string]) : void
{
def a = Convert.ToInt32(args[0]);
def b = Convert.ToInt32(args[1]);
Console.WriteLine("{0} + {1} = {2}", a, b, a + b);
Console.WriteLine("{0} - {1} = {2}", a, b, a - b);
Console.WriteLine("{0} * {1} = {2}", a, b, a * b);
Console.WriteLine("{0} / {1} = {2}", a, b, a / b); // truncates towards 0
Console.WriteLine("{0} % {1} = {2}", a, b, a % b); // matches sign of first operand
Console.WriteLine("{0} ** {1} = {2}", a, b, a ** b);
}
}
You may also check:How to resolve the algorithm N-queens problem step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Pangram checker step by step in the Scala programming language
You may also check:How to resolve the algorithm Cholesky decomposition step by step in the OCaml programming language
You may also check:How to resolve the algorithm Classes step by step in the 11l programming language
You may also check:How to resolve the algorithm Call an object method step by step in the PowerShell programming language