Q:

Rust program to calculate the area of Parallelogram

belongs to collection: Rust Basic Programs

0

Here, we will read the basealtitude of the Parallelogram from the user. Then we will calculate the area of Parallelogram and print the result.

Area of Parallelogram formula = b x h

 

Where b is the base and h is the height or altitude of the Parallelogram.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to calculate the area of the Parallelogram is given below. The given program is compiled and executed successfully.

// Rust program to calculate the 
// area of Parallelogram

use std::io;

fn main() 
{
    let mut base:f32    = 0.0;
    let mut altitude:f32= 0.0;
    let mut area:f32    = 0.0;
    
    let mut input1 = String::new();
    let mut input2 = String::new();
       
    println!("Enter base: ");
    io::stdin().read_line(&mut input1).expect("Not a valid string");
    base = input1.trim().parse().expect("Not a valid number");
    
    println!("Enter altitude: ");
    io::stdin().read_line(&mut input2).expect("Not a valid string");
    altitude = input2.trim().parse().expect("Not a valid number");

    area = base * altitude;
    
    println!("Area of Parallelogram is: {}", area);
}

Output:

Enter base: 
12.34
Enter altitude: 
34.56
Area of Parallelogram is: 426.47043

Explanation:

Here, we read the value of basealtitude from the user. Then we calculated the area of Parallelogram and printed the result.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Rust Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Rust program to calculate the area of Cube... >>
<< Rust program to calculate the area of Trapezium...