VN:F [1.9.22_1171]
Rating: 3.0/5 (2 votes cast)

Factorial of given number Shell Script

 

Problem Statement : Write a Shell program to find the Factorial of given number using Shell Script code.

Factorial of given number using Shell Script program code will ask user to enter number for which user want to calculate factorial . After calculating the factorial it will be printed to screen output.

Program is using while loop which is starting from entered number to 1 . It will then calculate the factorial of number using this method.

Algorithm for Finding Factorial of Number

Start with the entered number $n towards one . Multiply number $n by another variable which starts with one by reducing $n by one in each step.

Factorial of given number using Shell Script Output

Sample Output 1

nulls@ubuntu:~$ ./script.sh
enter a number
3
factorial of given no. is 6

Sample Output 2

nulls@ubuntu:~$ ./script.sh
enter a number
5
factorial of given no. is 120

Sample Output 3

nulls@ubuntu:~$ ./script.sh
enter a number
7
factorial of given no. is 5040

Sample Output 4

nulls@ubuntu:~$ ./script.sh
enter a number
7
factorial of given no. is 5040

Sample Output 5

nulls@ubuntu:~$ ./script.sh
enter a number
7
factorial of given no. is 5040