ADVERTISEMENT
ADVERTISEMENT

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

Rust | Calculating Square Root: Given a floating-value value, and we have to calculate the square 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 square root of the number using the powf() function.

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.

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.