Skip to content

Commit 30a5a83

Browse files
authored
Merge pull request #424 from ngweihow/feature/rust-circle-area
Rust: Find Area of Circle given Radius
2 parents f996e35 + e7eaff9 commit 30a5a83

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

rust/maths/ngweihow_areacircle.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
Simple Rust One Liner to calculate area of circle.
3+
Made to have fun and learn Rust. This is my first time writing working code in Rust.
4+
5+
Requires Cargo.
6+
@author: github.com/ngweihow
7+
*/
8+
use std::io;
9+
use std::f32::consts::PI;
10+
11+
fn main() {
12+
println!("Enter the radius of the circle you want to calculate the area of: ");
13+
14+
let mut input = String::new();
15+
io::stdin().read_line(&mut input)
16+
.expect("Failed to read line!");
17+
18+
let float_input = input.trim().parse::<f32>().expect("Invalid Input!");
19+
20+
println!("The area of your circle is {} unit squared!", area_of_circle(float_input));
21+
}
22+
23+
// Area of circle one liner.
24+
fn area_of_circle(r: f32) -> f32 { r.powf(2.0) * PI }

0 commit comments

Comments
 (0)