How to resolve the algorithm Arithmetic/Integer step by step in the LiveCode programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Arithmetic/Integer step by step in the LiveCode 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 LiveCode programming language
Source code in the livecode programming language
ask "enter 2 numbers (comma separated)"
if it is not empty then
put item 1 of it into n1
put item 2 of it into n2
put sum(n1,n2) into ai["sum"]
put n1 * n2 into ai["product"]
put n1 div n2 into ai["quotient"] -- truncates
put n1 mod n2 into ai["remainder"]
put n1^n2 into ai["power"]
combine ai using comma and colon
put ai
end if
-2,4 - power:16,product:-8,quotient:0,remainder:-2,sum:2
2,-4 - power:0.0625,product:-8,quotient:0,remainder:2,sum:-2
-2,-4 - power:0.0625,product:8,quotient:0,remainder:-2,sum:-6
2,4 - power:16,product:8,quotient:0,remainder:2,sum:6
11,4 - power:14641,product:44,quotient:2,remainder:3,sum:15
You may also check:How to resolve the algorithm Horner's rule for polynomial evaluation step by step in the Forth programming language
You may also check:How to resolve the algorithm Comments step by step in the Gri programming language
You may also check:How to resolve the algorithm Matrix transposition step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Deming's funnel step by step in the Factor programming language
You may also check:How to resolve the algorithm Execute a system command step by step in the Oz programming language