Sunday, March 10, 2024

Program 10 B.Sc Computer Science with Data analytics Linux and Shell Programming - Lab Bharathiar University - Write a shell script to find the factorial of given integer.

 

B.Sc Computer Science  with Data analytics

Linux and Shell Programming - Lab  

Bharathiar University 

Program 10-  Write a shell script to find the factorial of given integer. 


Source Code


# Function to calculate factorial
factorial() {
    num=$1
    fact=1
    while [ $num -gt 1 ]; do
        fact=$((fact * num))
        num=$((num - 1))
    done
    echo $fact
}

# Main program starts here

# Prompt the user to enter the number
    echo "Enter a number to find factorial: "
    read n

# Calculate the factorial of the given integer
result=$(factorial $n)
echo "The factorial of $n is: $result"


Sample OUTPUT:
 


No comments:

Post a Comment

Program 12 BCA Madras University BCA Object Oriented Programming using C++ Practical Madras University Program 12 Implement a telephone directory using files

  BCA Object Oriented Programming using C++ Practical Madras University  Program 12  Implement a telephone directory using files SOURCE CODE...