Q:

Rust program to calculate the square root of a number using the powf() function

belongs to collection: Rust Basic Programs

0

In this program, we will create a floating-point variable and find the square root of the number using the powf() function.

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 square root of a number is given below. The given program is compiled and executed successfully.

// Rust program to calculate the square root 
// of a number using the powf() function

fn main() 
{
    let num: f32 = 16.0;
    let result = num.powf(1.0/2.0);
    
    println!("Square root is: {}", result);
}

Output:

Square root is: 4

Explanation:

Here, we created a variable num of f32 type with initial value of 16.0. Then we calculated the square root of the number using the powf() function 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 calculate the cube root of a numbe...