Skip to content

Instantly share code, notes, and snippets.

@espeon
Created March 2, 2020 06:46
Show Gist options
  • Select an option

  • Save espeon/617fdd0ba81760d1fd9144098ee89c0d to your computer and use it in GitHub Desktop.

Select an option

Save espeon/617fdd0ba81760d1fd9144098ee89c0d to your computer and use it in GitHub Desktop.
use std::io;
fn main() {
println!("Input a number:");
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("Failed to read line");
let input: u32 = match input.trim().parse() {
Ok(num) => num,
Err(_) => return,
};
println!("{} F is {} degrees C", input, (f_to_c(input as f32)));
println!("your fibonacci number is {}",fibonacci(input as u32));
}
fn fibonacci(n: u32) -> u32 {
let i: u32 = n;
match i {
0 => 1,
1 => 1,
_ => fibonacci(i - 1) + fibonacci(i - 2),
}
}
fn f_to_c(n: f32) -> f32 {
return (n - 32.0) / 1.8;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment