You are on page 1of 2

Shell Programming

Exp.No:2.a
Menu Operation
Program:
echo Menu
echo 1.List of users
echo 2.Date
echo 3.Current working directory
echo 4.Calendar of the month
echo Enter your choice
read choice
case $choice in
1)who;;
2)date;;
3)pwd;;
4)cal 8 2008;;
esac
Exp.No:2.b
Program:
echo Enter the number
read n
fact=1
i=1
while [ $i -le $n ]
do
fact=`expr $fact \* $i`
i=`expr $i + 1`
done
echo Factorial of $n is $fact

Factorial

Exp.No:2.c
Program:

Fibonacci Series

echo Enter the number


read num
fib=0
a=0 b=1
c=0 i=1
echo Fibonacci Series
if [ $num -eq 0 ]
then
echo 1
fi
while [ $i -le $num ]
do
fib=`expr $fib + $a`
a=$b
b=$fib
echo $fib
i=`expr $i + 1`
done

Exp.No:2.d
Program:
echo Enter the number
read n
t=$n
s=0
while [ $n -gt 0 ]
do
r=`expr $n % 10`
s=`expr $s + \( $r \* $r \* $r \)`
n=`expr $n / 10`
done
if [ $t -eq $s ]
then
echo Number is Armstrong
else
echo Number is not Armstrong
fi

Armstrong Number

Exp.No:2.e
Program:

Prime Number

echo Enter the number


read n
i=1
k=0
if [ $n -eq 1 ]
then
echo The number is neither prime nor composite
fi
while [ $i -le $n -a $n -ne 1 ]
do
x=`expr $n % $i`
if [ $x -eq 0 ]
then
k=`expr $k + 1`
fi
i=`expr $i + 1`
done
if [ $k -eq 2 ]
then
echo The number is prime
else
echo The number is not prime
fi

You might also like