Tuesday, 11 June 2013

Shell program to display summation of 1+2+3+4………+n

Code:
echo Enter the value for n:
read num
sum=0
iter=1
while [ $iter -le $num ]
do
        let sum=$sum+$iter
        let iter=$iter+1
done
echo $sum


Output:

[ty2011330@localhost ~]$ sh summation.sh
Enter the value for n:
10
55

1 comment: