Find the factorial of a number coderinme

Find the factorial of number

Before Find the factorial, We should know that the factorial function (symbol: !) means to multiply a series of descending natural numbers.
4! = 4 × 3 × 2 × 1 = 24
5! = 5 * 4 * 3 * 2 * 1 = 120
So the rule is: n! = n × (n−1)!
Which just says “the factorial of any number is that number times the factorial of (1 smaller than that number)
But what about zero?
Zero Factorial is interesting … it is generally agreed that 0! = 1.
In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n
Let’s code to Find the factorial


if [ $# -lt 1 ]; then
echo "Usage: $0 num"
exit 1
let end=$1-1
for i in `seq 1 $end`; do
let num*=$i
echo $num

Output will be:


for more Linux questiom

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

A web developer(Front end and Back end), and DBA at Currently working as Salesforce Developer @ Tech Matrix IT Consulting Private Limited. Check me

Leave a reply:

Your email address will not be published.