Saturday, 16 July 2016

Write a shell script in Linux/Unix to solve the following---S=1.2+2.3+3.4+4.5+.....


tput clear
echo the sum of the series---1.2+2.3+3.4+4.5......
echo--------------------------------------------------
echo enter the no of element
read n
s=0.1
sum=0
i=0
while test $i -lt $n
do
s=`echo $s + 1.1 |bc` 
i=`expr $i + 1`
sum=`echo $sum + $s |bc`
done 
echo $sum


OUTPUT:

the sum of the series---1.2+2.3+3.4+4.5......
--------------------------------------------------
enter the no of element
5
17.0







No comments:

Post a Comment

Popular Posts