-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShell.sh
More file actions
118 lines (105 loc) · 1.39 KB
/
Shell.sh
File metadata and controls
118 lines (105 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# Name: Chirantan Joshi.
# Div: G
# Batch: G1
# Roll No.: PG13
# MATHEMATICAL OPERATIONS WITH CONTROL STRUCTURES
#!/bin/bash
echo "Enter the 2 numbers"
read num1
read num2
function add()
{
res=`expr $1 + $2`
return $res
}
function sub()
{
res=`expr $1 - $2`
echo $res
}
function mul()
{
res=`expr $1 \* $2`
return $res
}
function div()
{
echo "scale=5; $1 / $2" | bc
}
while :
do
echo -e "\n---MENU---\n1->Add\n2->Sub\n3->Mul\n4->Div\n5->Exit\n"
echo "Enter Your Choice: "
read ch
case $ch in
1) echo "Addition of two numbers is: "
add $num1 $num2
echo $res
;;
2) echo "Subtraction of two numbers is: "
sub $num1 $num2
;;
3) echo "Multiplication of two numbers is: "
mul $num1 $num2
echo $res
;;
4)echo "Division of two numbers is: "
div $num1 $num2
;;
5) exit
;;
*) echo "Wrong input!!"
esac
done
# OUTPUT:
# Enter the 2 numbers
#18
#6
#---MENU---
#1->Add
#2->Sub
#3->Mul
#4->Div
#5->Exit
#Enter Your Choice:
#1
#Addition of two numbers is:
#24
#---MENU---
#1->Add
#2->Sub
#3->Mul
#4->Div
#5->Exit
#Enter Your Choice:
#2
#Subtraction of two numbers is:
#12
#---MENU---
#1->Add
#2->Sub
#3->Mul
#4->Div
#5->Exit
#Enter Your Choice:
#3
#Multiplication of two numbers is:
#108
#---MENU---
#1->Add
#2->Sub
#3->Mul
#4->Div
#5->Exit
#Enter Your Choice:
#4
#Division of two numbers is:
#3.00000
#---MENU---
#1->Add
#2->Sub
#3->Mul
#4->Div
#5->Exit
#Enter Your Choice:
#5