Loading…
OS · Loops & numbers · Program 04 · In the record
write a shell script to input a number and print the factorial of that number
1#!/bin/bash2 3echo "Enter a number:"4read n5 6fact=17i=18 9while (( i <= n ))10do11 fact=$((fact * i))12 i=$((i + 1))13done14 15echo "Factorial of $n = $fact"5Enter a number: 5 Factorial of 5 = 120
Run program 04 in your browser
bash · just-bash. Change the code or the input, run it, break it, and see what happens.