0%

rust版本 斐波那契额数列

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use ::std::io;
fn main() {
let mut n = String::new();
io::stdin().read_line(&mut n).expect("输入错误");
let n: i64 = n.trim().parse().expect("不是数字");
let mut index = 0;
let mut first = 0;
let mut second = 1;
while index <= n {
if index == 0 || index == 1 {
println!("count {}", index);
} else {
let count: i64 = first + second;
first = second;
second = count;
println!("count {}", count);
}
index += 1;
}
}