The source code to calculate the area of the circle is given below. The given program is compiled and executed successfully.
// Rust program to calculate the area of circle
use std::io;
fn main() {
let mut radius:f32 = 0.0;
let mut area:f32 = 0.0;
let mut input = String::new();
println!("Enter radius: ");
io::stdin().read_line(&mut input).expect("Not a valid string");
radius = input.trim().parse().expect("Not a valid number");
//Caculate the area of circle
area = 3.14 * radius * radius;
println!("Area of circle: {}",area);
}
Output:
RUN 1:
Enter radius:
1.2
Area of circle: 4.5216007
RUN 2:
Enter radius:
5.15
Area of circle: 83.28066
RUN 3:
Enter radius:
10
Area of circle: 314
Explanation:
Here, we read the value of radius from the user and calculated the area of the circle. After that, we printed the result.
Program/Source Code:
The source code to calculate the area of the circle is given below. The given program is compiled and executed successfully.
Output:
Explanation:
Here, we read the value of radius from the user and calculated the area of the circle. After that, we printed the result.
need an explanation for this answer? contact us directly to get an explanation for this answer