How to resolve the algorithm Arithmetic/Integer step by step in the i programming language

Published on 12 May 2024 09:40 PM
#I

How to resolve the algorithm Arithmetic/Integer step by step in the i 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 i programming language

Source code in the i programming language

main
	a $= integer(in(' ')); ignore
	b $= integer(in('\n')); ignore
	
	print("Sum:"		, a + b)
	print("Difference:", a - b)
	print("Product:"	, a * b)
	print("Quotient:"	, a / b) // rounds towards zero
	print("Modulus:"	, a % b) // same sign as first operand
	print("Exponent:"	, a ^ b)
}

  

You may also check:How to resolve the algorithm Empty string step by step in the M2000 Interpreter programming language
You may also check:How to resolve the algorithm Hough transform step by step in the Raku programming language
You may also check:How to resolve the algorithm Apply a callback to an array step by step in the M2000 Interpreter programming language
You may also check:How to resolve the algorithm Luhn test of credit card numbers step by step in the Octave programming language
You may also check:How to resolve the algorithm Ethiopian multiplication step by step in the Smalltalk programming language