A simple Rust command-line application for checking whether a given number is a prime number.
- Interactive CLI: Continuously prompts the user to enter a number and checks its primality.
- Handles invalid input gracefully.
- Allows users to exit the program at any time by typing
exit. - Efficient primality test implementation for 64-bit unsigned integers.
- Rust (version 1.60 or newer recommended)
- A terminal or command prompt
Clone the repository and build the project using Cargo:
git clone https://github.com/hrosicka/prime-number.git
cd prime-number
cargo build --releaseRun the application with Cargo:
cargo run --releaseYou will be prompted to enter a number. The program will indicate whether the number is prime. Type exit to quit.
Enter a number (or 'exit' to quit): 17
The number 17 is a prime number.
Enter a number (or 'exit' to quit): 20
The number 20 is not a prime number.
Enter a number (or 'exit' to quit): exit
Program terminated.
The application uses an efficient algorithm to check whether a number is prime:
- Returns
falsefor numbers less than 2. - Returns
truefor 2. - Eliminates even numbers greater than 2.
- Checks divisibility up to the square root of the input number, skipping even numbers.
Lovingly crafted by Hanka Robovska
This project is licensed under the MIT License.