We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 9e64b75 + 877ecb1 commit 1738bd8Copy full SHA for 1738bd8
prime_number/bash/prime.sh
@@ -0,0 +1,32 @@
1
+#!/bin/bash
2
+# Bash implementation of
3
+# https://github.com/hacktoberfest17/programming/blob/master/prime_number/c/prime_number.c
4
+
5
6
+function isPrime {
7
+ INPUT=$1
8
+ COUNTER=3
9
+ RESULT=true
10
+ if (( INPUT < 2 )); then
11
+ RESULT=false
12
+ elif (( INPUT == 2 )); then
13
14
+ elif (( INPUT % 2 == 0 )); then
15
16
+ else
17
+ X=$(echo "sqrt(${INPUT})" | bc)
18
+ while (( COUNTER <= X )); do
19
+ if (( INPUT % COUNTER == 0 )); then
20
21
+ fi
22
+ ((COUNTER++))
23
+ done
24
25
+}
26
27
+isPrime $1
28
+if [[ "${RESULT}" == "true" ]]; then
29
+ echo "It's a prime!"
30
+else
31
+ echo "It's not a prime!"
32
+fi
0 commit comments