Wednesday, 20 February 2013

Program:To write a shell program to find the factorial of a given number ..

Program:To write a shell  program to find the factorial of a given number ..

clear
i=1
f=1
echo "Enter the n value:"
read n
while [ $i -le $n ]
do
f=`expr $f \* $i`
i=`expr $i + 1`
done
echo "The factorial of $n is":$f


/*-------------------------INPUT/OUTPUT----------
Enter the n value:
6
The factorial of 6 is:720
-bash-3.2$

---------------------------------------------*/

4 comments:

  1. nice one.........its so simple.....easy to understand.......4 line program over..:-)

    ReplyDelete
  2. simple one. easy to catch

    ReplyDelete
  3. int fact=1,n,c;
    For(c=1;c<=n;c++)
    {
    fact=fact*c;
    }

    ReplyDelete