-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicCalculations.sh
More file actions
69 lines (52 loc) · 1.83 KB
/
BasicCalculations.sh
File metadata and controls
69 lines (52 loc) · 1.83 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
#!/bin/sh
# Author: Boyeong Yoon (boyeong.nancy.yoon@gmail.com)
BasicCalculations(){
echo -e "\n===================================================="
echo "=============== BASIC CALCULATIONS ================="
echo -e "====================================================\n"
# Reads 5 or 10 integers from an user and stores in the array NUMBERS
echo "Enter 10 intergers (ENTER after each int): "
for i in {0..9}
do
read NUMBERS[$i]
if [ $i -eq 4 ]
then
echo -n "Stop?(y/n): "
read STOP
if [ $STOP == "y" ]
then
break
fi
fi
done
echo -e "\n\n\n"
# Performs the basic calculations
PRODUCT=1
SUM=0
MAX=${NUMBERS[0]}
MIN=${NUMBERS[0]}
for elem in ${NUMBERS[@]}
do
((PRODUCT*=$elem))
((SUM+=$elem))
(($elem < $MIN)) && MIN=$elem
(($elem > $MAX)) && MAX=$elem
done
AVG=$(($SUM/${#NUMBERS[@]}))
# Prints out the value of basic calculations
echo -n "You entered ${#NUMBERS[@]} numbers and they are... "
for elem in ${NUMBERS[@]}
do
echo -n "$elem "
done
echo -e "\n"
echo "The Product: $PRODUCT"
echo "The Sum: $SUM"
echo "The Average: $AVG"
echo "The Maximum: $MAX"
echo "The Minimum: $MIN"
echo -e "\n===================================================="
echo -e "======== THE END OF THE BASIC CALCULATIONS ========="
echo -e "====================================================\n\n\n"
}
BasicCalculations