Saturday, 16 July 2016

Write a shell script in Linux/Unix to find the sum of squares of n natural numbers.


tput clear
echo ENTER THE NUMBER OF ELEMENTS-
read n
i=1
sum=0
while test $i -le $n
do
p=`expr $i \* $i`
sum=`expr $sum + $p`
i=`expr $i + 1`
done
echo $sum


OUTPUT:

ENTER THE NUMBER OF ELEMENTS-
5
55



No comments:

Post a Comment

Popular Posts