I've made an application that calculates all the prime numbers between two given numbers and prints then into a .txt document... anything I can improve?
use std::io;
use std::fs::{OpenOptions};
use std::io::{Write, BufWriter};
fn main() {
loop{
let mut format = 1;
let mut input = String::new();
println!("Say a start for the prime loop! ");
io::stdin().read_line(&mut input).unwrap();
let start: u128 = input.trim().parse().unwrap();
let mut input = String::new();
println!("Say an end for the prime loop! ");
io::stdin().read_line(&mut input).unwrap();
let end: u128 = input.trim().parse().unwrap();
let path = "path/to/file.txt";
let f = OpenOptions::new()
.write(true)
.open(path)
.expect("Could not open file");
let mut f = BufWriter::new(f);
for i in start..end{
if prime(i) == true{
f.write_all(i.to_string().as_bytes()).expect("unable to write to file");
f.write_all(b"\t").expect("unable to write to file");
format += 1;
}
if format == 10{
f.write_all(b"\n").expect("unable to write to file");
format = 0;
}
}
}
}
fn prime(x: u128) -> bool {
if x == 4 || x == 6 || x == 8 || x == 9{ //The loop doesnt quite work for numbers below 10 so this is for those numbers
return false;
}
for i in 2..((x as f64).sqrt() as u128){
if x % i == 0 { return false; } //modulo to see if the number is dividable by variable i
}
true
}
```