Q:

Rust program to calculate the Surface Area and Volume of Sphere

belongs to collection: Rust Basic Programs

0

Here, we will read the radius from the user. Then we will calculate the surface area and volume of Sphere and print the result.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to calculate the surface area, volume of the Cone is given below. The given program is compiled and executed successfully.

// Rust program to calculate the 
// Surface Area and Volume of Sphere

use std::io;

fn main() 
{
    let mut radius:f32   =0.0;
    
    let mut area:f32    =0.0;
    let mut volume: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");
    
    volume = (4.0 / 3.0) * (3.14) * radius* radius* radius;
    area = 4.0 * (3.14) * radius* radius;

    println!("Volume of Sphere 	    : {}", volume);
    println!("Surface area of Sphere: {}", area);
}

Output:

RUN 1:
Enter radius: 
3.5
Volume of Sphere            : 179.50334
Surface area of Sphere: 153.86002

RUN 2:
Enter radius: 
12.3
Volume of Sphere            : 7790.831
Surface area of Sphere: 1900.2025

Explanation:

Here, we read the radius from the user. Then we calculated the surface area, volume of the Sphere and printed the result.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Rust Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Rust program to read coordinate points and determi... >>
<< Rust program to calculate the surface area, the vo...