Arithmetic Operators Example 3

 #!bin/bash
#arthemetic Operators

echo "enter two numbers:"
read a b

c=`expr $a + $b`
echo "the sum of two Numbers: $c"

c=`expr $a - $b`
echo "the sub of two Numbers: $c"

c=`expr $a \* $b`
echo "the mul of two Numbers: $c"

c=`expr $a / $b`
echo "the div of two Numbers: $c"

#Double paranthesies
Sum=$(($a+$b+$c))
echo "Sum = $Sum"

echo "Addition of x & y"
echo $(( $a + $b ))

echo "Subtraction of x & y"
echo $(( $a - $b ))

echo "Multiplication of x & y"
echo $(( $a * $b ))


x=10
y=6
z=0
echo "Addition"
let "z = $(( x + y ))"
echo "z= $z"

echo "Substraction"
let "z = $((x - y ))"
echo "z= $z"

echo "Multiplication"
let "z = $(( x * y ))"
echo "z = $z"

echo "Division"
let "z = $(( x / y ))"
echo "z = $z"

echo "Exponentiation"
let "z = $(( x ** y ))"
echo "z = $z"

echo "Modular Division"
let "z = $(( x % y ))"
echo "z = $z"

let "x += 5"
echo "Incrementing x by 5, then x= "
echo $x

let "x -= 5"
echo "Decrementing x by 5, then x= "
echo $x
let "x *=5"

echo "Multiply of x by 5, then x="
echo $x
let "x /= 5"

echo "Dividing x by 5, x= "
echo $x
let "x %= 5"

echo "Remainder of Dividing x by 5, x="
echo $x