100-days-of-rust/Week-01/Day-06_Next-Prime/next_prime/src/main.rs
2024-07-31 21:14:40 +02:00

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"),
}
}