Q:

Rust program to calculate the volume of Cube

belongs to collection: Rust Basic Programs

0

Here, we will read the length of the side from the user. Then we will calculate the volume of the Cube and print the result.

The volume of Cube formula: side3 or a3

 

Where, side (or a) is the length of the side (i.e., edge)

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 area of Cube is given below. The given program is compiled and executed successfully.

// Rust program to calculate the 
// volume of Cube.

use std::io;

fn main() 
{
    let mut side:f32    =0.0;
    let mut volume:f32    =0.0;
    
    let mut input = String::new();
    
       
    println!("Enter length of side: ");
    io::stdin().read_line(&mut input).expect("Not a valid string");
    side = input.trim().parse().expect("Not a valid number");
    
    volume = side * side * side;
    
    println!("volume of Cube is: {}", volume);
}

Output:

Enter length of side: 
4.5
volume of Cube is: 91.125

Explanation:

Here, we read the length of the side from the user. Then we calculated the volume of the Cube 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 find the Surface Area and Volume o... >>
<< Rust program to calculate the area of Cube...