You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Program 2: Bash script to calculate the factorial of a number
#!/bin/bash# Read the number from user inputread -p "Enter a number: " number
# Initialize the factorial variable to 1
factorial=1
# Calculate the factorialfor(( i=1; i<=$number; i++))do
factorial=$((factorial * i))done# Print the resultecho"The factorial of $number is $factorial"
Program 3: Bash script to check if a string is a palindrome
#!/bin/bash# Read the string from user inputread -p "Enter a string: " string
# Reverse the string
reverse=$(echo "$string"| rev)# Compare the original string with the reversed stringif [ "$string"="$reverse" ];thenecho"The string is a palindrome"elseecho"The string is not a palindrome"fi