1. Home
  2. Bash
  3. Examples
  4. Bash – Find factorial of a number

Bash – Find factorial of a number

Find Factorial Of A Number in Bash Script

Q. Write a bash script to find the factorial of number?

What is a factorial number? A factorial number of any given number is the multiplication of all positive integers less than or equal to a given positive integer.

The factorial denoted with ! symbol. For example. The factorial of 5, 8 and 1 will be:

  • 5! = 4 × 3 × 2 × 1 = 24
  • 8! = 7 × 6 × 5 × 4 × 3 × 2 × 1 = 5040
  • 1! = 1

Example

A shell script to calculate the factorial of input number using for loop.

Another Example

A shell script to calculate the factorial of input number using while loop.

Was this article helpful to you? Yes 20 No 1
Advertisement