diff --git a/fibonacci/Cargo.lock b/fibonacci/Cargo.lock new file mode 100644 index 0000000..06a56e6 --- /dev/null +++ b/fibonacci/Cargo.lock @@ -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" diff --git a/fibonacci/Cargo.toml b/fibonacci/Cargo.toml new file mode 100644 index 0000000..d96d223 --- /dev/null +++ b/fibonacci/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "fibonacci" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/fibonacci/src/main.rs b/fibonacci/src/main.rs new file mode 100644 index 0000000..3faf433 --- /dev/null +++ b/fibonacci/src/main.rs @@ -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) + } +}