Skip to content

Instantly share code, notes, and snippets.

@0V
Created August 8, 2018 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0V/d1f31a2f00891061d1f7a7c98b65387b to your computer and use it in GitHub Desktop.
Save 0V/d1f31a2f00891061d1f7a7c98b65387b to your computer and use it in GitHub Desktop.
Wallis' Formula by Rust
use std::io;
fn main() {
println!("Please Input Count > ");
let mut count = String::new();
io::stdin().read_line(&mut count).expect("Failed to read line");;
let count: u64 = count.trim().parse().expect("Need u64");
println!("PI = {}",wallis_fomula(count));
}
fn wallis_fomula(count : u64) -> f64 {
let mut pi : f64 = 1.0;
for i in 1..count {
let n = (4 * i * i) as f64;
pi *= n / (n - 1.0);
}
let ans = pi * 2.0;
return ans;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment