Q:

Rust program to calculate the surface area, volume, and space diagonal of cuboids

belongs to collection: Rust Basic Programs

0

Here, we will read the heightwidthlength from the user. Then we will calculate the surface area, volume, and space diagonal of cuboids and print the result.

The surface area of cuboids:

A cuboid has 6 rectangular faces. To find the surface area of a cuboid, add the areas of all 6 faces. Consider that the length is l, width is w, and height is h of the prism and then the formula to calculate the Surface area of cuboids will be: 2lw + 2lh + 2hw

Volume of cuboids:

The formula to calculate the volume of cuboids (V) = whl

Space diagonal of cuboids: √(l2 + b2 +h2)

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, and space diagonal of cuboids is given below. The given program is compiled and executed successfully.

// Rust program to calculate the surface area, 
// volume, and space diagonal of cuboids

use std::io;

fn main() 
{
    let mut height:f32  =0.0;
    let mut width:f32   =0.0;
    let mut length:f32  =0.0;
    
    let mut area:f32    =0.0;
    let mut volume:f32  =0.0;
    let mut diagonal:f32=0.0;
      
    let mut input1 = String::new();
    let mut input2 = String::new();
    let mut input3 = 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 width: ");
    io::stdin().read_line(&mut input2).expect("Not a valid string");
    width = input2.trim().parse().expect("Not a valid number");
    
    println!("Enter length: ");
    io::stdin().read_line(&mut input3).expect("Not a valid string");
    length = input3.trim().parse().expect("Not a valid number");
    
    diagonal =(width * width).sqrt() + (length * length) + (height * height);
    area     = 2.0 * (width * length) + (length * height) + (height * width);
    volume   = width * length * height;

    println!("Volume of Cuboids is		  : {}", volume);
    println!("Surface area of Cuboids is  : {}", area);
    println!("Space diagonal of Cuboids is: {}", diagonal);
}

Output:

Enter height: 
10.2
Enter width: 
14.7
Enter length: 
16.5
Volume of Cuboids is              : 2474.01
Surface area of Cuboids is  : 803.34
Space diagonal of Cuboids is: 390.99

Explanation:

Here, we read the heightwidth, and length from the user. Then we calculated the surface area, volume, and space diagonal 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, the vo... >>
<< Rust program to find the Surface Area and Volume o...