Open Lyo001 opened 2 weeks ago
echo -n "Enter the value of n: " read n
sum=0 fact=1
for (( i=1; i<=n; i++ )); do fact=$((fact * i))
sum=$(echo "scale=10; $sum + 1/$fact" | bc) done
echo "Sum of the series up to 1/$n! is: $sum"
echo "Enter an integer:" read num reversed=" " while [ $num -ne 0 ] do digit=$((num % 10)) reversed="${reversed}${digit}" num=$((num / 10)) done echo "Reversed digits: $reversed"
read -p "Enter the employee's yearly salary: " yearly_salary
if [[ $yearly_salary -ge 5000 ]]; then
bonus=$(echo "scale=2; $yearly_salary * 0.05" | bc) echo "Bonus: ₹$bonus" else
bonus=250 echo "Bonus: ₹$bonus" fi
echo "Enter a list of numbers:" read -a num n=${#num[@]} for ((i=0; i<n; i++)) do for ((j=0; j<n-i-1; j++)) do if [ ${num[j]} -lt ${num[$((j+1))]}] then temp=${num[j]} num[j]=${num[$((j+1))]]} num[$((j+1))]=$temp fi done done echo "Ascending order: ${num[@]}"
for ((i=0; i<n; i++)) do for ((j=0; j<n-i-1; j++)) do if [ ${num[j]} -gt ${num[$((j+1))]}] then temp=${num[j]} num[j]=${num[$((j+1))]]} num[$((j+1))]=$temp fi done done echo "Descending order: ${num[@]}"
"Enter the employee's annual salary:" read salary if [ "$salary" -ge 5000 ]] then bonus=$(echo "$salary * 0.05" | bc) else bonus=250 fi echo "The bonus for the employee is: Rs $bonus"
!/bin/bash
factorial() { n=$1 fact=1 while [ $n -gt 1 ]; do fact=$((fact * n)) n=$((n - 1)) done echo $fact }
calculate_sum() { n=$1 sum=0
for (( i=1; i<=n; i++ )); do fact=$(factorial $i) term=$(echo "scale=10; 1/$fact" | bc) sum=$(echo "scale=10; $sum + $term" | bc) done
echo "Sum of the series up to 1/$n! is: $sum" }
echo -n "Enter the value of n: " read n
calculate_sum $n