The source code to calculate the area of Trapezium is given below. The given program is compiled and executed successfully.
// Rust program to calculate the
// area of Trapezium
use std::io;
fn main()
{
let mut base1:f32 = 0.0;
let mut base2:f32 = 0.0;
let mut height:f32 = 0.0;
let mut area:f32 = 0.0;
let mut input1 = String::new();
let mut input2 = String::new();
let mut input3 = String::new();
println!("Enter base1: ");
io::stdin().read_line(&mut input1).expect("Not a valid string");
base1 = input1.trim().parse().expect("Not a valid number");
println!("Enter base2: ");
io::stdin().read_line(&mut input2).expect("Not a valid string");
base2 = input2.trim().parse().expect("Not a valid number");
println!("Enter height: ");
io::stdin().read_line(&mut input3).expect("Not a valid string");
height = input3.trim().parse().expect("Not a valid number");
area = 0.5 * (base1 + base2) * height;
println!("Area of Trapezium is: {}", area);
}
Output:
Enter base1:
3
Enter base2:
4
Enter height:
1
Area of Trapezium is: 3.5
Explanation:
Here, we read the value of base1, base2, and height from the user. Then we calculated the area of the Trapezium and printed the result.
Program/Source Code:
The source code to calculate the area of Trapezium is given below. The given program is compiled and executed successfully.
Output:
Explanation:
Here, we read the value of base1, base2, and height from the user. Then we calculated the area of the Trapezium and printed the result.
need an explanation for this answer? contact us directly to get an explanation for this answer