Write a shell script to print the factorial of first n natural numbers.

 echo "Enter the Number"

read num
i=1
j=1
res=1
if test $j -eq 1
then
echo "The Factorial for the $j Number is="$j
j=`expr $j + 1 `
fi
while [ $j -le $num ]
do
while [ $i -le $j ]
do
res=`expr $res \* $i `
i=`expr $i + 1 `
done
echo "The Factorial for the $j Number is="$res
res=1
i=1
j=`expr $j + 1 `
done

ex:- sh filename.sh

Comments

Popular posts from this blog

CLOOK DISK SCHEDULING

LOOK Disk Scheduling