# Program :
1 .To calculate the area and circumference of the circle given the radius
echo "Enter the radius of the circle:"
read r
area=$(bc <<< "3.14 * $r * $r")
circum=$(bc <<< "3.14 * 2 * $r")
echo "Area of the circle: $area"
echo "Circumference of the circle: $circum"
2. menu driven calculator using case
i="y"
while [ "$i" = "y" ]; do
clear
echo "MENU - Calculator"
echo "1. Addition"
echo "2. Subtraction"
echo "3. Multiplication"
echo "4. Division"
echo "Enter your choice: "
read ch
echo "Enter first number: "
read n1
echo "Enter second number: "
read n2
case $ch in
1) result=$((n1 + n2))
echo "Sum = $result";;
2) result=$((n1 - n2))
echo "Subtraction = $result";;
3) result=$((n1 * n2))
echo "Multiplication = $result";;
4) result=$(echo "scale=2; $n1 / $n2" | bc)
echo "Division = $result";;
*) echo "Invalid choice";;
esac
echo "Do you want to continue? (y/n)"
read i
done
3.Find greatest among three numbers
echo "Enter three numbers separated by spaces:"
read a b c
largest=$a
if [ "$b" -gt "$largest" ]; then
largest=$b
fi
if [ "$c" -gt "$largest" ]; then
largest=$c
fi
echo "Largest of $a, $b, and $c is $largest"
4.mean and standard deviation of three numbers
echo "Enter three numbers separated by spaces:"
read a b c
sum=$(echo "$a + $b + $c" | bc)
mean=$(echo "scale=4; $sum / 3" | bc)
sd=$(echo "($a - $mean)^2 + ($b - $mean)^2 + ($c - $mean)^2" | bc)
sd=$(echo "scale=6; sqrt($sd / 3)" | bc -l)
echo "Mean = $mean"
echo "Standard Deviation = $sd"
5.Reverse of a number
clear
echo "Enter a number:"
read n
rev=0
while [ "$n" -gt 0 ]; do
rev=$((rev * 10 + n % 10))
n=$((n / 10))
done
echo "Reversed number: $rev"
6.Fibonacci series
echo "How many terms to generate?"
read n
x=0
y=1
echo "Fibonacci Series up to $n terms:"
echo "$x"
echo "$y"
for ((i = 2; i < n; i++)); do
z=$((x + y))
echo "$z"
x=$y
y=$z
done
7.Check for armstrong mumber
echo "Program to check Armstrong number"
echo "Enter the number: "
read n
sum=0
old=$n
while [ "$n" -gt 0 ]; do
sd=$((n % 10))
sum=$((sum + sd * sd * sd))
n=$((n / 10))
done
if [ "$old" -eq "$sum" ]; then
echo "Number is Armstrong"
else
echo "Number is not Armstrong"
fi
8.factorial of a number
echo "Enter a number to find its factorial:"
read fact
ans=1
for ((i = 1; i <= fact; i++)); do
ans=$((ans * i))
done
echo "Factorial of $fact is $ans"
9.prime numbers
echo "Program to print prime numbers"
echo "Enter the limit:"
read n
echo "Prime numbers are:"
for ((i = 2; i <= n; i++)); do
flag=0
for ((j = 2; j * j <= i; j++)); do
if ((i % j == 0)); then
flag=1
break
fi
done
if ((flag == 0)); then
echo -n "$i "
fi
done
echo
10.palindrom string
clear
echo "Enter the string:"
read string
stringrev=$(echo "$string" | rev)
if [ "$string" = "$stringrev" ]; then
echo "Input string is a palindrome"
else
echo "String is not a palindrome"
fi
11.words,lines in file
clear
echo "Enter the filename:"
read file
if [ ! -f "$file" ]; then
echo "File not found!"
exit 1
fi
echo "Contents of the file:"
echo "##############"
cat "$file"
echo "##############"
lines=$(wc -l < "$file")
words=$(wc -w < "$file")
chars=$(wc -c < "$file")
echo "Number of Lines = $lines"
echo "Number of Words = $words"
echo "Number of Characters = $chars"
12. gross from DA,HRA
clear
echo "Enter the name of the employee:"
read name
echo "Enter the Basic Pay of the employee:"
read BP
echo "Enter the DA percentage:"
read DA
echo "Enter the HRA percentage:"
read HRA
# Calculate Gross Salary
Gross=$(echo "scale=2; $BP + ($BP * $DA / 100) + ($BP * $HRA / 100)" | bc)
echo "Gross Salary of $name is Rs. $Gross"
13. average through command line
clear
sum=0
n=$#
if [ $n -eq 0 ]; then
echo "No numbers provided!"
exit 1
fi
for i in "$@"; do
sum=$((sum + i))
done
avg=$(echo "scale=2; $sum / $n" | bc)
echo "Average of the numbers = $avg"
14 good morning,evening based on time
clear
hour=$(date +"%H")
echo "Current time: $(date +"%T")"
if [ "$hour" -ge 6 ] && [ "$hour" -lt 12 ]; then
echo "Good morning"
elif [ "$hour" -ge 12 ] && [ "$hour" -lt 17 ]; then
echo "Good afternoon"
else
echo "Good evening"
fi
15. vowels and consonents
clear
echo "Enter the string:"
read word
vowels=$(echo "$word" | sed 's/[^aeiouAEIOU]//g')
consonants=$(echo "$word" | sed 's/[^bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ]//g')
echo "Total characters: ${#word}"
echo "Vowels: ${#vowels}"
echo "Consonants: ${#consonants}"