echo "Enter a number: "
read n
i=1
val=0
cal=0
while [ $i -le $n ]
do
if [ `expr $i % 2` -ne 0 ]
then
val=`expr $i \* $i \* $i`
cal=`expr $cal + $val`
echo -e "+$val \c"
else
val=`expr $i \* $i`
cal=`expr $cal - $val`
echo -e "-$val \c"
fi
i=`expr $i + 1`
done
echo -e "\nSum is $cal"
--------------------------------------------------------------------------------------------------------------
OUTPUT
Enter a number:10
+1 -4 +27 -16 +125 -36 +343 -64 +729 -100
Sum is 1005
0 comments:
Post a Comment