functions, loops and control flow

This commit is contained in:
2025-12-20 18:13:04 +00:00
parent 83fc3600b8
commit 04c6e7e66a
12 changed files with 300 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
[package]
name = "fibonacci"
version = "0.1.0"
edition = "2024"
[dependencies]

View File

@@ -0,0 +1,29 @@
use std::io;
fn fib(x: i32) -> i32 {
if x == 1 {
return 0;
} else if x == 2 {
return 1;
} else {
return fib(x - 1) + fib(x - 2);
}
}
fn main() {
println!("welcome to the fibo party!");
println!("which fibonacci number would you like to see?");
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("error storing user input");
let input: i32 = input
.trim()
.parse()
.expect("error converting to number: did you enter a non-number?");
println!("fibonacci number {input} is {}", fib(input));
}