CEP: C: Introduces TODO file
[lcapit-junk-code.git] / prime.sh
blob5ebc6eee1f4e84f6cd0df8f106b4351bad330870
1 #!/bin/bash
3 # Check if a number is prime (brute force)
5 # Luiz Fernando N. Capitulino
6 # <lcapitulino@gmail.com>
8 is_prime()
10 local i
11 local res
12 local number=$1
13 local max=$((${number} - 1))
15 for ((i = 2; i < $max; i++)); do
16 res=$(($number % $i))
17 if [ $res -eq 0 ]; then
18 return 0
20 done
22 return 1
25 if [ $# -ne 1 ]; then
26 echo "usage: prime.sh < number >"
27 exit 1
30 is_prime $1
31 if [ $? -eq 1 ]; then
32 echo is prime