Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- is_prime() {
- local number=$1
- if ((number <= 1)); then
- echo "false"
- return
- fi
- if ((number <= 3)); then
- echo "true"
- return
- fi
- if ((number % 2 == 0 || number % 3 == 0)); then
- echo "false"
- return
- fi
- local i=5
- while ((i * i <= number)); do
- if ((number % i == 0 || number % (i + 2) == 0)); then
- echo "false"
- return
- fi
- ((i += 6))
- done
- echo "true"
- }
- for i in {1..1000}
- do
- if [ "$(is_prime "$i")" == "true" ]; then
- echo "$i is a prime number."
- else
- continue
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement