SHELL PROGRAM
Write a program to find a factorial of a number ? |Shell Program|
#!/bin/bash
echo "Enter a number"
read num
fact=1
while [ $num -gt 1 ]
do
fact=$((fact * num))
num=$((num - 1))
done
echo "factorial=$fact"
OUTPUT
Enter a number
5
factorial=120
echo "Enter a number"
read num
fact=1
while [ $num -gt 1 ]
do
fact=$((fact * num))
num=$((num - 1))
done
echo "factorial=$fact"
OUTPUT
Enter a number
5
factorial=120
Post a Comment
0 Comments