mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2024-10-29 22:17:23 +01:00
feat(solutions): add is-prime-number/rust/function
This commit is contained in:
parent
9e751c53d9
commit
29f8ac1da4
7
challenges/is-prime-number/solutions/rust/function/Cargo.lock
generated
Normal file
7
challenges/is-prime-number/solutions/rust/function/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "rust_application"
|
||||
version = "1.0.0"
|
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "rust_application"
|
||||
version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,3 @@
|
||||
# is-prime-number/rust/function
|
||||
|
||||
Created by [@Divlo](https://github.com/Divlo) on 29 December 2022.
|
@ -0,0 +1,19 @@
|
||||
use std::io;
|
||||
|
||||
fn is_prime_number(number: u32) -> bool {
|
||||
for iteration in 2..number {
|
||||
if number % iteration == 0 {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut number = String::new();
|
||||
io::stdin()
|
||||
.read_line(&mut number)
|
||||
.expect("Failed to read `stdin` line.");
|
||||
let number: u32 = number.trim().parse().expect("Please type a number!");
|
||||
println!("{}", is_prime_number(number));
|
||||
}
|
Loading…
Reference in New Issue
Block a user