1.write A Shell Script Program To Display The Multiplication Table
1.write A Shell Script Program To Display The Multiplication Table
#!/bin/sh
echo "Enter the lower and upper limit :"
read n m
if [ $m -lt $n ]
then
for i in $(seq $m 1 $n)
do
for j in $(seq 1 1 10)
do
mul=`expr $i \* $j`
echo "$i * $j = $mul"
done
printf "\n"
done
else
for i in $(seq $n 1 $m)
do
for j in $(seq 1 1 10)
do
mul=`expr $i \* $j`
echo "$i * $j = $mul\t"
done
printf "\n"
done
fi
2.Write a shell script program to find the given number is an Armstrong or not
#!/bin/sh
echo "enter the number:"
read n
sum=0
t=$n
echo "n=$t"
while [ $t -gt 0 ]
do
rem=`expr $t % 10`
t=`expr $t / 10`
r3=`expr $rem \* $rem \* $rem`
sum=`expr $sum + $r3`
done
if [ $sum -eq $n ]
then
echo "$n is an Armstrong number"
else
echo "$n is not an Armstrong number"
fi
3.Write a shell script program to display the Fibonacci series
#!/bn/sh
echo "enter the limit :"
read n
x=0
y=1
echo "fibonacci series are:"
echo "$x"
echo "$y"
for i in $(seq 3 1 $n)
do
z=`expr $x + $y`
echo "$z"
x=$y
y=$z
done
5.Write a shell script program to count the number of Vowels in a given string
#!/bin/sh
echo "Enter the string :"
read str
r=0
i=1
len=`expr length $str`
echo "number of character is : $len"
while [ $i -le $len ]
do
ch=`expr $str | cut -c $i`
case $ch in
[AEIOUaeiou])v=`expr $v + 1`;;
esac
i=`expr $i + 1`
done
echo "Number of vowels in a string is : $v \n"
#!/bin/sh
clear
echo "Enter number1:\c"
read n1
echo "Enter operator(+,-,*,/):\c"
read op
echo "enter number2:\c"
read n2
if [ "$op" = "+" ]
then
calc=`echo $n1 + $n2 |bc`
echo "\n$n1 + $n2 = $calc\n"
elif [ "$op" = "-" ]
then
calc=`echo $n1 - $n2 |bc`
echo "\n$n1 - $n2 = $calc\n"
elif [ "$op" = "*" ]
then
calc=`echo $n1 \* $n2 |bc`
echo "\n$n1 * $n2 = $calc\n"
elif [ "$op" = "/" ]
then
calc=`echo $n1 / $n2 |bc`
echo "\n$n1 / $n2 = $calc\n"
else
echo "Invalid operator\n"
fi
7 Write a shell script program to find the given number is palindrome or not
#!/bin/sh
clear
echo "enter the number"
read n
num=$n
rev=0
rem=0
while [ $n -gt 0 ]
do
rem=`expr $n % 10`
rev=`expr $rev \* 10 + $rem`
n=`expr $n / 10`
done
if [ $num -eq $rev ]
then
echo "Given number is palindrome"
else
echo "Given number is not palindrome"
fi
8 Write a shell script program to accept the integer as an argument and print it as in
string format
#!/bin/sh
clear
echo "Enter a number"
read n
echo "Given number is: $n\n"
i=1
len=`expr length $n`
while [ $i -le $len ]
do
ch=`expr $n | cut -c $i`
case $ch in
0)echo "Zero\t";;
1)echo "One\t";;
2)echo "two\t";;
3)echo "three\t";;
4)echo "four\t";;
5)echo "five\t";;
6)echo "six\t";;
7)echo "seven\t";;
8)echo "eight\t";;
9)echo "nine\t";;
esac
i=`expr $i + 1`
done
echo "\n"
10.Write a shell script program to accept numbers below 50 and to print display the
square of each. This should continue as long as the user Wishes
#!/bin/sh
clear
wish=1
while [ $wish -eq 1 ]
do
echo "Enter the number :\n"
read n
if [ $n -le 50 ]
then
sq=`expr $n \* $n`
echo "square of $n is $sq \n"
else
echo "Number not in given range\n"
fi
wish=0
echo "Do you wish to continue?(1/0):\n"
read wish
if [ $wish -eq 1 ]
then continue
else
echo "Thanking you...\n"
exit
fi
done