-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprimo.sh
More file actions
executable file
·34 lines (26 loc) · 787 Bytes
/
primo.sh
File metadata and controls
executable file
·34 lines (26 loc) · 787 Bytes
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
#!/bin/bash
echo "Please, input a number: "
read NUM
DIV=1
CONT=0
echo "\n\n-------------------- DOING THE MATH --------------------\n"
while [[ $DIV -le $NUM ]]; do
RES=$[ $NUM / $DIV ]
REM=$[ $NUM % $DIV ]
if [[ $REM -eq 0 ]]; then
echo -e "${NUM}/${DIV} = ${RES}\nRemain: ${REM}"
CONT=$[ $CONT + 1 ]
echo "Total dividers (so far): ${CONT}"
# else
# echo -e "${NUM}/${DIV} = ${RES} \n Remain: ${REM}"
# echo "Total dividers (so far): ${CONT}"
fi
DIV=$[ $DIV + 1 ]
done
echo -e "\n\n------------------- CONCLUSION --------------------\n"
if [[ $CONT -eq 2 ]]; then
echo "${NUM} is a prime number, since it is divided by only ${CONT} different numbers!"
else
echo "${NUM} is not a prime number, sice it is divided by ${CONT} different numbers!"
fi
echo "Done! :D"