Program for Fibonacci Series
echo To find the Fibonacci Series
echo Enter a number
read b
c=0
e=1
echo $c
echo $e
while test $e -le $b
do
echo $d
d=`expr $c + $e`
c=$e
e=$d
done
OUTPUT
To find the Fibonacci series
enter a numbers :3
0
1
1
2
3
Program for Armstrong Number Between 1 to 500
echo AMSTRONG NUMBERS BETWEEN 1 TO 500
for (( i=1 ; i<= 500 ; i++ ))
do
temp=$i
n=$i
ams=0
while test $n -ne 0
do
d=`expr $n % 10`
ams=`expr $ams + $d \* $d \* $d`
n=`expr $n / 10`
done
if test $temp -eq $ams
then
echo $ams
fi
done
OUTPUT:
ARMSTRONG NUMBER BETWEEN 1 TO 500
1
153
370
371
407
PROGRAM FOR REVERSE OF NUMBER:
echo enter the number to be reversed
read n
rev=0
while test $n -ne 0
do
a=`expr $n % 10`
rev=`expr $rev \* 10 + $a`
n=`expr $n / 10`
done
echo REVERSE OF A NUMBER =$rev
OUTPUT:
enter the number to be reversed
25463
REVERSE OF A NUMBER=36452
Program for Greatest of 3 Number
echo greatest of 3 numbers
echo enter the numbers
read a
read b
read c
if test $a -gt $b -a $a -gt $c
then
echo a is greater
elif test $b -gt $c
then
echo b is greater
else
echo c is greater
fi
done
OUTPUT
great of 3 numbers
enter the numbers
25
65
80
c is greater
Program for Prime Number Between 1 to 50
echo PRIME NOS BETWEEN 1 TO 50
for (( i=2 ; i<=50 ; i++ ))
do
if test $i -eq 2 -o $i -eq 3 -o $i -eq 5 -o $i -eq 7
then
echo $i
elif test `expr $i % 2` -ne 0 -a `expr $i % 3` -ne 0 -a `expr $i % 7` -ne 0
then
echo $i
fi
done
OUTPUT:
PRIME NUMBERS BETWEEN 1 TO 50
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
Program for String Palindrome
echo Reversing the number
echo Enter the string
read a
b=`expr $a | wc -c`
c=`expr $b - 1`
echo $c
while test $b -gt 0
do
e=`expr $a | cut -c $b`
d=`echo $d$e`
b=`expr $b - 1`
done
echo The reversed string is $d
if test $a = $d
then
echo It is a palindrome
else
echo It is not a palindrome
fi
done
OUTPUT
enter a string
malayalam
10
the reverse sting is malayalam
It is a palindrome
Program for Employee Details
echo Enter the number of employees
read n
for (( i=1 ; i<=$n ; i++ ))
do
echo Enter the employee ID Number
read empno
echo Enter the employee name
read ename
echo Enter the employees basic salary
read bsal
if test $bsal -ge 10000
then
hra=1000
da=700
ta=500
elif test $bsal -lt 10000 -a $bsal -ge 5000
then
hra=750
da=500
ta=350
elif test $bsal -lt 5000 -a $bsal -ge 3000
then
hra=500
da=300
ta=200
else
hra=300
da=200
ta=100
fi
netsal=`expr $hra + $da + $ta + $bsal`
echo --------------------------------------------------------
echo PAY SLIP OF $ename
echo --------------------------------------------------------
echo Empname $ename
echo Empno $empno
echo Basicpay=$bsal
echo HRA=$hra
echo TA=$ta
echo DA=$da
echo Netpay=$netsal
done
OUTPUT:
enter the number of employees
2
enter the employee id number 4777
enter the employee name kumaran
enter the employee basic salary25000
empname=kumaran
empno=4777
basicpay=25000
HRA=1000
DA=700
TA=500
netpay=27200
enter the employee id number 4778
enter the employee name srini
enter the employee basic salary 4000
empname=srini
empno=4778
basicpay=4000
HRA=500
TA=200
DA=300
netpay=5000
Program for Performing Arithmetic Operators
echo Program For Arithmetic Operator
echo Enter The First Number
read a
echo Enter The Second Number
read b
add=`expr $a + $b`
sub=`expr $a - $b`
mul=`expr $a \* $b`
div=`expr $a / $b`
echo OUTPUT
echo "The Sum is:"$add
echo "The Difference is:"$sub
echo "The Product is:"$mul
echo "The Quotient is:"$div
OUTPUT:
Program for Arthmetic Operator
Enter the First number
15
Enter the Second number
5
The Sum is :20
The Difference is :10
The Product is :75
The Quotient is :3
Program for Student Details
echo enter the number of students
read n
for (( i=1 ; i<=$n ; i++ ))
do
echo Enter the Register Number
read reg
echo Enter the student name
read sname
echo Enter the 5 subjects marks
read m1
read m2
read m3
read m4
read m5
tot=`expr $m1 + $m2 + $m3 + $m4 + $m5`
avg=`expr $tot / 5`
echo =============================================
echo $sname STUDENT DETAILS
echo ==============================================
echo STUDENT NAME=$sname
echo STUDENT REGNO=$reg
echo STUDENT AVERAGE=$tot
if test $avg -ge 75
then
echo GRADE="S" $name passed with DISTINCTION
elif test $avg -lt 75 -a $avg -ge 60
then
echo GRADE="A" $name passed with FIRST CLASS
elif test $avg -lt 60 -a $avg -ge 50
then
echo GRADE="B" $name passed with SECOND CLASS
elif test $avg -lt 50 -a $avg -ge 45
then
echo GRADE="C" $name passed with THIRD CLASS
else
echo GRADE="U" $name FAILED
fi
done
OUTPUT:
enter the number of students
1
Enter the Register Number
453467
Enter the student name
Kumaran
Enter the 5 subjects marks
90
98
89
90
100
=============================================
Kumaran STUDENT DETAILS
==============================================
STUDENT NAME=Kumaran
STUDENT REGNO=453467
STUDENT AVERAGE=467
GRADE=S passed with DISTINCTION
Program for Multiplication Table
echo Program for Multiplication Table
i=1
echo Enter the value of the table
read n
echo output
while test $i -le $n
do
echo The multiplication table for $i
for j in 1 2 3 4 5 6 7 8 9 10
do
a=`expr $i \* $j`
echo $i x $j = $a
done
i=`expr $i + 1`
done
OUTPUT
Program for Multiplication Table
Enter the value of the table
2
The multiplication table for:1
1x1=1
1x2=2
1x3=3
1x4=4
1x5=5
1x6=6
1x7=7
1x8=8
1x9=9
1 x 10 = 10
The multiplication table for:2
2x1=2
2x2=4
2x3=6
2x4=8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18
2 x 10 = 20