Home »
Rust »
Rust Programs
Rust program to calculate the cube root of a number
Rust | Calculating Cube Root: Given a floating-point value, we have to calculate the cube root of the given value.
Submitted by Nidhi, on October 08, 2021
Problem Solution:
In this program, we will create a floating-point variable and find the cube root of the number using the powf() function.
Program/Source Code:
The source code to calculate the cube root of a number is given below. The given program is compiled and executed successfully.
// Rust program to calculate the
// cube root of a number
fn main()
{
let num: f32 = 27.0;
let result = num.powf(1.0/3.0);
println!("Cube root is: {}", result);
}
Output:
Cube root is: 3
Explanation:
Here, we created a variable num of f32 type with the initial value of 27.0. Then we calculated the cube root of the number using the powf() function and printed the result.
Rust Basic Programs »