2 个不稳定版本
0.2.0 | 2019年11月3日 |
---|---|
0.1.0 | 2019年10月31日 |
#1266 in 算法
430KB
1. 斐波那契数列
斐波那契数列是一系列数字
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
下一个数字是通过将前面的两个数字相加得到的。
例如
0 + 1 = 1 ,
1 + 1 = 2
等等...
想要了解更多关于斐波那契数列的信息
2. 图片
下面的图片是斐波那契数列的简要故事
3. 图形解释
上面的两张图片是斐波那契数列的图形解释
4. 源代码快照
5. 代码块
/* This program is for printing series of first 'N' (user given limit) Fibonacci Numbers on the console */
use std::io;
pub fn fibonacci() {
println!("\n Please enter the quantity of Fibonacci number series\n ");
let mut num = String::new();
io::stdin().read_line(&mut num).expect("no data is given");
let num : u32 = num.trim().parse().unwrap();
let mut first : usize = 0;
let mut second : usize = 1;
let mut initial : usize = 0;
let mut next : usize;
println!("\n The following is the Fibonacci series\n");
println!(" **************************************\n");
// for first N Fibonacci Series, we used 0..num Range pattern with num excluding
for _x in 0..num {
if initial <= 1 {
next = initial;
initial= 1+initial;
}
else{
next = first + second;
first = second;
second = next;
}
println!(" Number-{} : {}, \n",_x+1, next);
}
}
"编写无错误的程序有两种方法;只有第三种有效。"
~AlanPerils