Rust Program to Calculate the Surface Area, Volume, and Space Diagonal of Cuboids

You are currently viewing Rust Program to Calculate the Surface Area, Volume, and Space Diagonal of Cuboids

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

// 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

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply