How to resolve the algorithm Arithmetic/Integer step by step in the UNIX Shell programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Arithmetic/Integer step by step in the UNIX Shell 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 UNIX Shell programming language
Source code in the unix programming language
#!/bin/sh
read a; read b;
echo "a+b = " `expr $a + $b`
echo "a-b = " `expr $a - $b`
echo "a*b = " `expr $a \* $b`
echo "a/b = " `expr $a / $b` # truncates towards 0
echo "a mod b = " `expr $a % $b` # same sign as first operand
#!/bin/sh
read a; read b;
echo "a+b = $((a+b))"
echo "a-b = $((a-b))"
echo "a*b = $((a*b))"
echo "a/b = $((a/b))" # truncates towards 0
echo "a mod b = $((a%b))" # same sign as first operand
You may also check:How to resolve the algorithm Associative array/Merging step by step in the Wren programming language
You may also check:How to resolve the algorithm Non-decimal radices/Convert step by step in the J programming language
You may also check:How to resolve the algorithm String prepend step by step in the SparForte programming language
You may also check:How to resolve the algorithm Bitmap/Write a PPM file step by step in the C# programming language
You may also check:How to resolve the algorithm Ordered words step by step in the Clojure programming language