Crates.io | fibonacci_series |
lib.rs | fibonacci_series |
version | 0.2.0 |
source | src |
created_at | 2019-10-31 10:08:51.562201 |
updated_at | 2019-11-03 23:40:18.809389 |
description | Fibonacci Sequence. The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... The next number is found by adding up the two numbers before it. |
homepage | https://doc.rust-lang.org/book/title-page.html |
repository | https://github.com/huzefagul92/PIAIC_IOT_BATCH-2_Q1.git |
max_upload_size | |
id | 177119 |
size | 443,390 |
/* 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