16 lines
336 B
Text
16 lines
336 B
Text
fn factorial(anon n: i64) throws -> i64 {
|
|
if n < 0 {
|
|
throw Error::from_string_literal("Factorial's operand must be non-negative")
|
|
}
|
|
mut result = 1
|
|
for i in 1..(n + 1) {
|
|
result *= i
|
|
}
|
|
return result
|
|
}
|
|
|
|
fn main() {
|
|
for i in 0..11 {
|
|
println("{} factorial is {}", i, factorial(i))
|
|
}
|
|
}
|