#!/bin/bash
#arithmetic operations
a=10
b=20
echo "a = $a b = $b"
val=`expr $a + $b`
echo "a + b : $val"
val=`expr $a - $b`
echo "a - b : $val"
val=`expr $a \* $b`
echo "a * b : $val"
val=`expr $b / $a`
echo "b / a : $val"
val=`expr $b % $a`
echo "b % a : $val"
readonly n=100
total=`expr $val + $n`
echo $total
#n=$total
#echo $n
#floating point arithmetic
x=10.1
y=20.2
echo "$x + $y" | bc
echo "$x - $y" | bc
echo "$x * $y" | bc
echo "$x / $y" | bc
#arithmetic operations
a=10
b=20
echo "a = $a b = $b"
val=`expr $a + $b`
echo "a + b : $val"
val=`expr $a - $b`
echo "a - b : $val"
val=`expr $a \* $b`
echo "a * b : $val"
val=`expr $b / $a`
echo "b / a : $val"
val=`expr $b % $a`
echo "b % a : $val"
readonly n=100
total=`expr $val + $n`
echo $total
#n=$total
#echo $n
#floating point arithmetic
x=10.1
y=20.2
echo "$x + $y" | bc
echo "$x - $y" | bc
echo "$x * $y" | bc
echo "$x / $y" | bc
No comments:
Post a Comment