Loading…
OS · Functions & patterns · Program 22 · In the record
shell function to input a number and print the factorial of that number
1#!/bin/bash2 3factorial()4{5 local n=$16 local fact=17 8 for (( i = 2; i <= n; i++ ))9 do10 fact=$((fact * i))11 done12 13 echo $fact14}15 16echo "Enter a number:"17read n18 19echo "Factorial of $n = $(factorial $n)"6Enter a number: 6 Factorial of 6 = 720
Run program 22 in your browser
bash · just-bash. Change the code or the input, run it, break it, and see what happens.