Create Fibonacci sequence calculator

This commit is contained in:
2025-10-17 15:26:16 -07:00
parent a3826fc6ad
commit d03d482fc6

View File

@@ -1,3 +1,24 @@
use std::io;
fn main() {
println!("Hello, world!");
println!("Rust Fibonacci: Calculate the nth element of the Fibonacci sequence.");
let mut n = String::new();
println!("What would you like n to equal? ");
io::stdin()
.read_line(&mut n)
.expect("Enter an integer.");
let n = n.trim().parse().expect("Failed to parse.");
let mut f_previous = 0;
let mut f = 1;
for _each in 1..n {
println!("{}", f + f_previous);
let f_placeholder = f_previous;
f_previous = f;
f = f + f_placeholder;
}
}