Rust program to calculate the power of float number using powi() function

Rust | powi() function example: Write a Rust program to calculate the power of float number using powi() function.
Submitted by Nidhi, on October 08, 2021

Problem Solution:

In this program, we will calculate the power of a floating-point number using the powi() function. Here we will use the number as float type and power is an integer type.

Program/Source Code:

The source code to calculate the power of float number using the powi() function is given below. The given program is compiled and executed successfully.

// Rust program to calculate the power 
// of float number using powi() 
// function

fn main() 
{
    let num: f32 = 3.24;
    let result = num.powi(4);
    
    println!("Result is: {}", result);
}

Output:

Result is: 110.1996

Explanation:

Here, we created a variable num of i32 type with the initial value of 3.24. Then we calculated the power 4 for the number num using the powi() function and printed the result.

Rust Basic Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.