dave on Nostr: fn factorial(number: i32) -> i32 { // Base Case if number == 0 { return 1; } // ...
fn factorial(number: i32) -> i32 {
// Base Case
if number == 0 {
return 1;
}
// Recursive Case
return number * factorial(number-1);
}
fn main() {
println!("Factorial of 4 is: {}", factorial(4));
}
Published at
2023-02-07 17:21:55Event JSON
{
"id": "143be9b3c70918f4695484104dbb4dfae107d8441193bed8938b6a2dc50873d9",
"pubkey": "5c10ed0678805156d39ef1ef6d46110fe1e7e590ae04986ccf48ba1299cb53e2",
"created_at": 1675790515,
"kind": 1,
"tags": [
[
"e",
"3d36bf9009a0223baa45107fd4d1c13cff51a1fee133fb78fb2ac28df9b6852a",
"",
"root"
],
[
"e",
"404d53743ff45db94ca4e2c011a2ae0b79fb3d56e8cc58e451fc4078ee6964da",
"",
"reply"
],
[
"p",
"aae9cfdb3113db442c1ad8d4c670a28091e5267748e71d2c1e189e423dbea1bf"
]
],
"content": "fn factorial(number: i32) -\u003e i32 {\n // Base Case\n if number == 0 {\n return 1;\n }\n\n // Recursive Case\n return number * factorial(number-1);\n}\n\nfn main() {\n println!(\"Factorial of 4 is: {}\", factorial(4));\n}",
"sig": "17aa69e394c2d676e8121abc9c8f60f935bf43f7f98ecf159f2aee2367a6ec356769a85236d43ba6de77f4296a8f016da001b97bab58254b753be99e2bda6adc"
}