100% found this document useful (1 vote)
948 views

1.write A Shell Script Program To Display The Multiplication Table

The document contains 10 shell script programs with the following functions: 1. Display multiplication tables 2. Check if a number is Armstrong 3. Display the Fibonacci series 4. Check if a number is prime 5. Count vowels in a string 6. Basic calculator 7. Check if a number is a palindrome 8. Convert an integer to words 9. Calculate salary details 10. Display squares of numbers below 50 and continue until user chooses to exit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
948 views

1.write A Shell Script Program To Display The Multiplication Table

The document contains 10 shell script programs with the following functions: 1. Display multiplication tables 2. Check if a number is Armstrong 3. Display the Fibonacci series 4. Check if a number is prime 5. Count vowels in a string 6. Basic calculator 7. Check if a number is a palindrome 8. Convert an integer to words 9. Calculate salary details 10. Display squares of numbers below 50 and continue until user chooses to exit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 6

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

4.Write a shell script program to find the given number is prime or no


#!/bin/sh
echo "enter the number:\n"
read n
count=0
num=`expr $n / 2`
for i in $(seq 2 1 $num)
do
n1=`expr $n % $i`
if [ $n1 -eq 0 ]
then
count=`expr $count + 1`
break
fi
done
if [ $count -eq 0 ] && [ $n -ne 1 ]
then
echo "$n is prime number\n"
else
echo "$n is not prime number\n"
fi

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"

6.Shell script for a simple calculator

#!/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"

9 Find Basic Salary,Hra,DA, And Calculate the Net Salary


#!/bin/sh
clear
echo "Enter basic salary"
read b
hra=0
da=0
if [ $b -gt 1500 ]
then
hra=500
da=`expr $b \* 98 / 100`
else
hra=`expr $b \* 10 / 100`
da=`expr $b \* 90 / 100`
fi
gs=`expr $b + $hra + $da`
it=`expr $b \* 30 / 100`
nt=`expr $gs - $it`
echo "Gross salary is: Rs.$gs"
echo "Net salary is: Rs.$nt"
echo "Details:"
echo "Basic:Rs.$b"
echo "HRA:Rs.$hra"
echo "DA:Rs.$da"
echo "IT:Rs.$it"

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

You might also like