Rust program to calculate the power of a given number

Hey reader! Do you know one thing? Using this article, you can easily Rust program to calculate the power of a given number.

Rust program to calculate the power of a given number

Rust program to calculate the power of a given number

// Rust program to calculate the 
// power of given number

use std::io;

fn main() {
    let mut n:u32 = 0;
    let mut p:u32 = 0;
    let mut res:u32 = 0;
    
    let mut input1 = String::new();
    let mut input2 = String::new();
    
    println!("Enter number: ");
    io::stdin().read_line(&mut input1).expect("Not a valid string");
    n = input1.trim().parse().expect("Not a valid number");

    println!("Enter power: ");
    io::stdin().read_line(&mut input2).expect("Not a valid string");
    p = input2.trim().parse().expect("Not a valid number");

    res = n.pow(p);
    
    println!("Result is: {}",res);
}
RUN 1:
Enter number: 
2
Enter power: 
3
Result is: 8

RUN 2:
Enter number: 
10
Enter power: 
3
Result is: 1000

RUN 3:
Enter number: 
7
Enter power: 
5
Result is: 16807

Final Words

We are confident that you will understand the Rust program to calculate the power of a given number article. Also if you have any information regarding this article please let us know in the comment box way comment.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment