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$
---------------------------------------------*/
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$
---------------------------------------------*/
nice one.........its so simple.....easy to understand.......4 line program over..:-)
ReplyDeletesimple one. easy to catch
ReplyDeleteint fact=1,n,c;
ReplyDeleteFor(c=1;c<=n;c++)
{
fact=fact*c;
}
thank u..
ReplyDelete