The source code to demonstrate the use of abs() function is given below. The given program is compiled and executed successfully.
// Rust program to demonstrate the
// use of abs() function
fn main() {
let mut n1:i32 = -5;
let mut n2:i32 = 7;
let mut res:i32 = 0;
res = n1.abs();
println!("Absolute value is n1: {}",res);
res = n2.abs();
println!("Absolute value is n2: {}",res);
}
Output:
Absolute value is n1: 5
Absolute value is n2: 7
Explanation:
Here, we created two integer variables n1 and n2. Then we found the absolute value of n1 and n2 using the abs() function. After that, we printed the result.
Program/Source Code:
The source code to demonstrate the use of abs() function is given below. The given program is compiled and executed successfully.
Output:
Explanation:
Here, we created two integer variables n1 and n2. Then we found the absolute value of n1 and n2 using the abs() function. After that, we printed the result.
need an explanation for this answer? contact us directly to get an explanation for this answer