Shell programming it will perform the basic air thematic operation like addition subtraction, multiplication and division. Using if and else if condition in the bash shell programming. Arithmetic operation is done by the bash shell with expr keyword. It will compare there value by –eq by through equal operation.

Source code bash shell Programming Algorithm

echo "Enter the values"

read i

read j

echo "Enter 1 for addition"

echo "Enter 2 for subtraction"

echo "Enter 3 for multiplication"

echo "Enter 4 for division"

echo "enter choice"

read a

x=1

y=2

z=3

m=4

if [ $a -eq $x ]

then

l=`expr $i + $j`

echo “ The addition is ”

echo $l

elif [ $a -eq $y ]

then

k=`expr $i - $j`

echo “ The subtraction is ”

echo $k

elif [ $a -eq $z ]

then

p=`expr $i \* $j`

echo “ The multipliction is ”

echo $p

elif [ $a -eq $m ]

then

s=`expr $i / $j`

echo “ The division is ”

echo $s

fi

OUTPUT ARITHMETIC OPERATION CS1252 Operating Systems lap

[redhat35@localhost Rhel5]$ sh arithmetic.sh

Enter the values

3

5

Enter 1 for addition

Enter 2 for subtraction

Enter 3 for multiplication

Enter 4 for division

Enter choice

3

The multiplication is

15

MULTIPLICATION TABLE

Source code bash shell Programming Algorithm

echo “ Enter the number ”

read i

echo “ $i table ”

j=1

while [ $i –le 12 ]

do

l=`expr $j \* $j = $l`

echo "$j * $i = $l"

j=`expr $j + 1`

done

OUTPUT MULTIPLICATION TABLE CS1252 Operating Systems lap

[redhat35@localhost Rhel5]$ sh multable.sh

Enter the number

2

2 table

1 * 2 = 2

2 * 2 = 4

3 * 2 = 6

4 * 2 = 8

5 * 2 = 10

6 * 2 = 12

7 * 2 = 14

8 * 2 = 16

9 * 2 = 18

10 * 2 = 20

11 * 2 = 22

12 * 2 = 24

Source code bash shell Programming Algorithm

echo "Enter the values"

read i

read j

echo "Enter 1 for addition"

echo "Enter 2 for subtraction"

echo "Enter 3 for multiplication"

echo "Enter 4 for division"

echo "enter choice"

read a

x=1

y=2

z=3

m=4

if [ $a -eq $x ]

then

l=`expr $i + $j`

echo “ The addition is ”

echo $l

elif [ $a -eq $y ]

then

k=`expr $i - $j`

echo “ The subtraction is ”

echo $k

elif [ $a -eq $z ]

then

p=`expr $i \* $j`

echo “ The multipliction is ”

echo $p

elif [ $a -eq $m ]

then

s=`expr $i / $j`

echo “ The division is ”

echo $s

fi

OUTPUT ARITHMETIC OPERATION CS1252 Operating Systems lap

[redhat35@localhost Rhel5]$ sh arithmetic.sh

Enter the values

3

5

Enter 1 for addition

Enter 2 for subtraction

Enter 3 for multiplication

Enter 4 for division

Enter choice

3

The multiplication is

15

MULTIPLICATION TABLE

Source code bash shell Programming Algorithm

echo “ Enter the number ”

read i

echo “ $i table ”

j=1

while [ $i –le 12 ]

do

l=`expr $j \* $j = $l`

echo "$j * $i = $l"

j=`expr $j + 1`

done

OUTPUT MULTIPLICATION TABLE CS1252 Operating Systems lap

[redhat35@localhost Rhel5]$ sh multable.sh

Enter the number

2

2 table

1 * 2 = 2

2 * 2 = 4

3 * 2 = 6

4 * 2 = 8

5 * 2 = 10

6 * 2 = 12

7 * 2 = 14

8 * 2 = 16

9 * 2 = 18

10 * 2 = 20

11 * 2 = 22

12 * 2 = 24

## 0 comments:

Post a Comment