ADVERTISEMENT
ADVERTISEMENT

Rust program to calculate the area of Cube

Given the length of the side, and we have to calculate the area of Cube using Rust program.
Submitted by Nidhi, on September 30, 2021

Problem Solution:

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

Area of Cube formula: 6 x side2 or 6a2

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

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 area of Cube

use std::io;

fn main() 
{
    let mut side:f32    =0.0;
    let mut area: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");
    
    area = 6.0 * side * side;
    
    println!("Area of Cube is: {}", area);
}

Output:

Enter length of side: 
2.67
Area of Cube is: 42.773403

Explanation:

Here, we read the length of the side from the user. Then we calculated the area of the Cube 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.