We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 3fcb5cf + a681db0 commit cda17c7Copy full SHA for cda17c7
factorial/shell/factorial.sh
@@ -0,0 +1,18 @@
1
+#!/bin/bash
2
+fact=1
3
+#taking input from user
4
+echo -e "Please enter a finite possitive number"
5
+read n
6
+#if enter value less than 0
7
+if [ $n -le 0 ] ; then
8
+echo "invalid number"
9
+exit
10
+fi
11
+#factorial logic
12
+if [ $n -gt 0 ] ; then
13
+for((i=$n;i>=1;i--))
14
+do
15
+fact=`expr $fact \* $i`
16
+done
17
18
+echo "The factorial of $n is $fact"
0 commit comments