How to calculate the surface area of cylinder in Rust

1 Answer

0 votes
fn main() {
    let radius:f32 = 6.0;
    let height:f32 = 19.0;
      
    let pi:f32 = std::f32::consts::PI;
      
    let cylinder_surface_area1:f32 = (2.0 * pi * radius * height) + (2.0 * pi * (radius * radius));
    let cylinder_surface_area2:f32 = 2.0 * pi * radius * (radius + height);
      
    println!("Cylinder Surface Area = {}", cylinder_surface_area1);
    println!("Cylinder Surface Area = {}", cylinder_surface_area2);
}
  
  
  
  
  
/*
run:
     
Cylinder Surface Area = 942.4778
Cylinder Surface Area = 942.4778
     
*/

 



answered May 10, 2023 by avibootz
edited May 10, 2023 by avibootz

Related questions

1 answer 84 views
1 answer 159 views
1 answer 130 views
1 answer 122 views
1 answer 118 views
1 answer 124 views
...