ADVERTISEMENT
ADVERTISEMENT

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

Given the radius and height of the Cone, we have to calculate the surface area, the volume of the Cone using the Rust program.
Submitted by Nidhi, on October 01, 2021

Problem Solution:

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

The surface area of Cone:

To calculate the surface area of Cone (Right Circular Cone), the formula is:

cone area

The volume of Cone:

To calculate the volume of Cone (Right Circular Cone), the formula is:

cone volume

Where,

  • r : Radius of the Cone
  • h : Height of the Cone

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 height, radius from the user. Then we calculated the surface area, volume of the Cone and printed the result.

Rust Basic Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.