The source code to find the square root of the given number is given below. The given program is compiled and executed successfully.
// Rust program to find the
// square root of given number
use std::io;
fn main() {
let mut n:f32 = 0.0;
let mut res:f32 = 0.0;
let mut input = String::new();
println!("Enter number: ");
io::stdin().read_line(&mut input).expect("Not a valid string");
n = input.trim().parse().expect("Not a valid number");
res = n.sqrt();
println!("Square root is: {}",res);
}
Output:
RUN 1:
Enter number:
36
Square root is: 6
RUN 2:
Enter number:
18
Square root is: 4.2426405
RUN 3:
Enter number:
-1
Square root is: NaN
Explanation:
Here, we read the number from the user. Then we calculated the square root of a given number using the sqrt() function and printed the result.
Program/Source Code:
The source code to find the square root of the given number is given below. The given program is compiled and executed successfully.
Output:
Explanation:
Here, we read the number from the user. Then we calculated the square root of a given number using the sqrt() function and printed the result.
need an explanation for this answer? contact us directly to get an explanation for this answer