Skip to content

Commit

Permalink
Merge pull request mouredev#4220 from marcoatrs/main
Browse files Browse the repository at this point in the history
Reto mouredev#4 - Rust
  • Loading branch information
kontroldev authored Jul 21, 2023
2 parents d71e9ef + 7881036 commit 6c26935
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions Retos/Reto #4 - PRIMO, FIBONACCI Y PAR [Media]/rust/marcoatrs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
fn is_prime(num: i32) -> bool {
if num == 2 {
return true;
}
if num < 2 || is_even(num) {
return false;
}
for n in (3..num).step_by(2) {
if num % n == 0 {
return false;
}
}
return true;
}

fn is_fibonacci(number: i32) -> bool {
let x = 5 * number.pow(2);
let psr = f64::sqrt((x + 4) as f64);
let nsr = f64::sqrt((x - 4) as f64);
if psr == psr.floor() {
return true;
} else if nsr == nsr.floor() {
return true;
}
return false;
}

fn is_even(num: i32) -> bool {
let res: bool;
if num % 2 == 0 {
res = true;
} else {
res = false;
};
return res;
}

fn pfe(num: i32) {
let prime: &str;
let fibo: &str;
let even: &str;
if is_prime(num) {
prime = "es primo";
} else {
prime = "no es primo";
}

if is_fibonacci(num) {
fibo = "fibonacci";
} else {
fibo = "no es fibonacci";
}

if is_even(num) {
even = "es par";
} else {
even = "es impar";
}

println!("{} {}, {} y {}", num, prime, fibo, even);
}

fn main() {
pfe(2);
pfe(7);
}

0 comments on commit 6c26935

Please sign in to comment.