Small Arithmetic Scripts
All Scripts written under Ubuntu 7.04
10 to the Power of x
#!/bin/bash # 10 to the power of x read -p "x:" x echo -n "10^$x=" echo 10^$x | bc
odd or even
#!/bin/bash # Odd or Even # Got the idea from # http://bash.cyberciti.biz/academic/odd_or_even.sh.php read -p "x:" x ore=$(( $x % 2 )) if [ $ore -eq 0 ] then echo "$x is an even number" else echo "$x is an odd number" fi
Pi
#!/bin/bash #Pi read -p "# of decimal places:" n echo -n "pi=" echo "scale=$n; 4*a(1)" | bc -l
x to the power of y
#!/bin/bash # x to the power of y read -p "x:" x read -p "y:" y echo -n "$x^$y=" echo "scale=4; $x^$y" | bc
square
#!/bin/bash # square read -p "x:" x echo -n "$x^2=" echo "scale=4; $x*$x" | bc
square root
#!/bin/bash # square root read -p "x:" x echo "Square root does not provide decimal" echo -n "square root of $x=" echo sqrt($x) | bc

Leave a Reply