24 lines
643 B
Rust
24 lines
643 B
Rust
use next_prime::next_prime;
|
|
use std::io::{self, Write};
|
|
|
|
fn main() {
|
|
let mut buffer = String::new();
|
|
|
|
print!("Give me an integer, and I will return the first prime found from that: ");
|
|
io::stdout().flush().expect("Failed to flush stdout.");
|
|
|
|
io::stdin()
|
|
.read_line(&mut buffer)
|
|
.expect("Error while trying to read the number.");
|
|
|
|
let num: usize = buffer
|
|
.trim()
|
|
.parse()
|
|
.expect("The input inserted is not a valid integer");
|
|
|
|
match next_prime(num) {
|
|
Some(x) => println!("Here's the first prime found from {}: {}", num, x),
|
|
None => println!("None found"),
|
|
}
|
|
}
|