Showing posts with label factorial. Show all posts
Showing posts with label factorial. Show all posts

Functions - factorial of a number

 # Functions - factorial of a number 


def fnfact(N):

if(N==0):

return 1

else:

return(N*fnfact(N-1))


Num = int(input("Enter Number : "))

print("Factorial of", Num, "is", fnfact(Num))

Shell Programming - Factorial of a number

# Shell Programming
# Factorial of a number

echo -n "Enter N : "
read n
i=1
fact=1
while [ $i -le $n ]
do
fact=`expr $fact \* $i`
i=`expr $i + 1`
done

echo "Factorial of $n = $fact"