You are on page 1of 4

FALL SEMESTER 2023-2024

NAME: Chethan N V

REG.NO: 21BCE0427

Course Title: Operating Systems Lab

Course Code: BCSE303P

Slot: L43+L44

EXPERIMENT NO : LAB ASSIGNMENT – 1

FACULTY NAME: Hiteshwar Kumar Azad


Question

Aim: To Find the Factorial of a number using “for” loop in shell


programming

Algorithm:
Step 1: Start
Step 2: Open file with sh extension
Step 3: write shell programming
Step 3: Input n
Step 4: initialize factorial to 1
Step 5: declare for loop from i=1 to n
Step 6: Print factorial
Step 7: Stop

Program:
echo "Name: Chethan N V"
echo "Reg No: 21BCE0427"
echo "Enter a number to find factorial"
read n
f=1
for((i=1;i<=n;i++))
{
f=$(bc <<< "$f*$i")
}
echo $n"! = "$f
Screenshots:
Sample Input 1:
25
Sample Output 1:
25! = 15511210043330985984000000

Sample Input 2:
10
Sample Output 2:
10! = 3628800

You might also like