Compare commits
2 commits
852f5a9b76
...
bca900b692
Author | SHA1 | Date | |
---|---|---|---|
bca900b692 | |||
c6e001b549 |
6 changed files with 73 additions and 0 deletions
7
fibonacci/Cargo.lock
generated
Normal file
7
fibonacci/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 = "fibonacci"
|
||||
version = "0.1.0"
|
6
fibonacci/Cargo.toml
Normal file
6
fibonacci/Cargo.toml
Normal file
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "fibonacci"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
17
fibonacci/src/main.rs
Normal file
17
fibonacci/src/main.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
use std::io;
|
||||
|
||||
fn main() {
|
||||
let mut input = String::new();
|
||||
println!("Please enter the number to calculate the Fibonacci sequence for.");
|
||||
io::stdin().read_line(&mut input).expect("An error occurred!");
|
||||
let value: u32 = input.trim().parse().unwrap();
|
||||
println!("Result: {}", fibonacci(value));
|
||||
}
|
||||
|
||||
fn fibonacci(end: u32) -> u32 {
|
||||
if end <= 1 {
|
||||
1
|
||||
} else {
|
||||
fibonacci(end - 2) + fibonacci(end - 1)
|
||||
}
|
||||
}
|
7
hottie/Cargo.lock
generated
Normal file
7
hottie/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 = "hottie"
|
||||
version = "0.1.0"
|
6
hottie/Cargo.toml
Normal file
6
hottie/Cargo.toml
Normal file
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "hottie"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
30
hottie/src/main.rs
Normal file
30
hottie/src/main.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
use std::io;
|
||||
|
||||
fn main() {
|
||||
let mut input = String::new();
|
||||
let celsius: bool = {
|
||||
loop {
|
||||
println!("Please enter the unit you wish to convert from:");
|
||||
println!("0: Celsius");
|
||||
println!("1: Fahrenheit");
|
||||
io::stdin().read_line(&mut input).expect("An error occurred!");
|
||||
|
||||
break match input.trim().parse::<i32>() {
|
||||
Err(_) => {
|
||||
println!("The specified input `{}` is invalid.", input.trim());
|
||||
continue;
|
||||
},
|
||||
Ok(value) => {
|
||||
value == 0
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let mut input = String::new();
|
||||
println!("Please enter the value to convert:");
|
||||
io::stdin().read_line(&mut input).expect("An error occurred!");
|
||||
let value: f64 = input.trim().parse().unwrap();
|
||||
|
||||
println!("result: {}", if celsius { value * 9.0 / 5.0 + 32.0 } else { (value - 32.0) * 5.0 / 9.0 })
|
||||
}
|
Loading…
Reference in a new issue