0% found this document useful (0 votes)
23 views

Shell Programming Exp - No:2.a Menu Operation Program

This document contains shell scripts for several programs: a menu program, a factorial program, a Fibonacci series program, a program to check for Armstrong numbers, and a program to check for prime numbers. Each program uses shell commands like echo, read, expr, and test conditions to complete its task. The menu program displays a menu and uses a case statement to run different commands based on the user's choice. The other programs take a user-input number and perform calculations or checks on that number to determine properties like its factorial, place in the Fibonacci series, or if it is an Armstrong or prime number.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Shell Programming Exp - No:2.a Menu Operation Program

This document contains shell scripts for several programs: a menu program, a factorial program, a Fibonacci series program, a program to check for Armstrong numbers, and a program to check for prime numbers. Each program uses shell commands like echo, read, expr, and test conditions to complete its task. The menu program displays a menu and uses a case statement to run different commands based on the user's choice. The other programs take a user-input number and perform calculations or checks on that number to determine properties like its factorial, place in the Fibonacci series, or if it is an Armstrong or prime number.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 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