Q:

Rust program to find the Surface Area and Volume of the Cylinder

belongs to collection: Rust Basic Programs

0

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

Cylinder volume formula: πr2h

Cylinder surface area formula: 2πrh+2πr2

Where r is the radius and h is the height.

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 find the Surface Area and volume of the cylinder is given below. The given program is compiled and executed successfully.

// Rust program to find the Surface 
// Area and volume of the cylinder

use std::io;

fn main() 
{
    let mut radius:f32    =0.0;
    let mut height:f32    =0.0;
    let mut area:f32    =0.0;
    let mut volume:f32    =0.0;
    
    let mut input1 = String::new();
    let mut input2 = String::new();
       
    println!("Enter radius: ");
    io::stdin().read_line(&mut input1).expect("Not a valid string");
    radius = input1.trim().parse().expect("Not a valid number");
    
    println!("Enter height: ");
    io::stdin().read_line(&mut input2).expect("Not a valid string");
    height = input2.trim().parse().expect("Not a valid number");
    
    volume = 3.14 * radius * radius * height;
    area   = 2.0 * 3.14 * radius * (radius + height);
    
    println!("Volume of Cylinder is: {}", volume);
    println!("Surface area of Cylinder is: {}", area);
}

Output:

Enter radius: 
5
Enter height: 
3.2
Volume of Cylinder is: 251.2
Surface area of Cylinder is: 257.48

Explanation:

Here, we read the radiusheight from the user. Then we calculated the surface area and volume of the Cylinder 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 calculate the surface area, volume... >>
<< Rust program to calculate the volume of Cube...