AIM:
To write a shell program for the following:
(i) Sum of series.
(ii) Factorial of a number.
ALGORITHM:
Sum of series:
· Get the range of series
· intialise the sum to zero and increment the variable.
· Check whether increment value is less than equal to range.
· if so calculate the sum and value.
· Display the result.
· Terminate the program.
Factorial of a number:
· Get the number to find factorial.
· Initialize the variable and find the factorial.
· Check whether the value is lesser than zero.
· if true calculate factorial.
PROGRAM SOURCE CODE
(i) Sum of digits:
echo ”enter the range”
read range
s=0
i=1
while [ $i – le $range ]
do
s= `expr $s + $i `
i=`expr $i + 1`
done
echo “the sum is : $s”
(ii) Factorial of a number:
echo “enter the number”
Read n
i=1
j=1
while [ $i –le $n ]
do
j=`expr $i \* $j`
i=`expr $i + 1`
done
echo “factorial : $j”
CONCLUSION:
Thus the shell program to find the sum of series and factorial computation are written and executed successfully.
0 Comments