Logo 
Search:

Unix / Linux / Ubuntu Articles

Submit Article
Home » Articles » Unix / Linux / Ubuntu » Homework HelpRSS Feeds

Program to calculate the factorial of a number

Posted By: Mena Schmidt     Category: Unix / Linux / Ubuntu     Views: 42075

Write a program to calculate the factorial of a number.

Code for Program to calculate the factorial of a number in Unix / Linux / Ubuntu

echo "Total no of factorial wants"
read fact

ans=1
counter=0
while [ $fact -ne $counter ]
do
        counter=`expr $counter + 1`
        ans=`expr $ans \* $counter`
done
echo "Total of factorial is $ans"

-------------------------------------------------------------------
output
-------------------------------------------------------------------
Total no of factorial wants
5
Total of factorial is 120
  
Share: 


Didn't find what you were looking for? Find more on Program to calculate the factorial of a number Or get search suggestion and latest updates.

Mena Schmidt
Mena Schmidt author of Program to calculate the factorial of a number is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!