Q:

Rust program to calculate the surface area, the volume of the Cone

belongs to collection: Rust Basic Programs

0

Problem Solution:

Here, we will read the heightradius from the user. Then we will calculate the surface area and volume of Cone 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, volume of Cone

use std::io;

fn main() 
{
    let mut height:f32  =0.0;
    let mut radius: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 height: ");
    io::stdin().read_line(&mut input1).expect("Not a valid string");
    height = input1.trim().parse().expect("Not a valid number");
    
    println!("Enter radius: ");
    io::stdin().read_line(&mut input2).expect("Not a valid string");
    radius = input2.trim().parse().expect("Not a valid number");
    
    volume = (1.0 / 3.0) * (3.14) * radius * radius * height;
    area = (3.14) * radius * (radius + (radius * radius + height * height).sqrt());

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

Output:

RUN 1:
Enter height: 
2.5
Enter radius: 
1.2
Volume of Cone    : 3.7680006
Surface area of Cone: 14.970586

RUN 2:
Enter height: 
12.4
Enter radius: 
25.6
Volume of Cone    : 8505.699
Surface area of Cone: 4344.3564

Explanation:

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