Quardiatic Equation
Write A Shell Script To Find The Roots Of a Quardiatic Equation Shell Script: clear echo general form ax2+bx+c=0 echo enter a read a echo enter b read b echo enter c read c d=`echo " scale=4;$b * $b - 4 * $a * $c " | bc` if [ $d -lt 0 ] then echo roots are imaginary else echo roots are real g=`echo " scale=4; -1 * $b + sqrt($d) " | bc` h=`echo " scale=4; -1 * $b - sqrt($d) " | bc` e=`echo " scale=4; 2 * $a " | bc` f=`echo " scale=4; $g / $e " | bc` y=`echo " scale=4; $h / $e " | bc` echo the roots are $f and $y fi OUTPUT: [admin@localhost ~]$ sh quard.sh general form ax2+bx+c=0 enter a 1 enter b -1 enter c -12 roots are real the roots are 4.0000 and -3.0000
Tags:
Shell Script
0 comments