【发布时间】:2019-12-06 03:57:56
【问题描述】:
我需要在我的项目中计算 21 阶乘。
fn factorial(num: u64) -> u64 {
match num {
0 => 1,
1 => 1,
_ => factorial(num - 1) * num,
}
}
fn main() {
let x = factorial(21);
println!("The value of 21 factorial is {} ", x);
}
运行此代码时,出现错误:
thread 'main' panicked at 'attempt to multiply with overflow', src\main.rs:5:18
【问题讨论】: