find the surface area of a cube in rust

To find the surface area of a cube in Rust, we need to know the length of its sides or its edge. Once we know the length of its sides, we can use the formula to find the surface area of a cube, which is:

SA = 6a^2

where SA is the surface area of the cube and a is the length of its side.

Here's how to write a Rust program to find the surface area of a cube:

main.rs
use std::io;

fn main() {
    println!("Enter the length of the cube's sides: ");
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();

    let length: f64 = input.trim().parse().unwrap();
    let surface_area = 6.0*length*length;

    println!("The surface area of the cube is: {}", surface_area);
}
331 chars
13 lines

In this program, we first ask the user to enter the length of the cube's sides. We then read the user's input and store it in a variable called length which is of type f64. We then calculate the surface area of the cube using the formula and store it in a variable named surface_area. Finally, we print out the surface area of the cube using println! statement.

related categories

gistlibby LogSnag