Area of trapezium

Write a program to find the area of trapezium.

Example

Input: side1=4,side2=5,height=3
Output: 13.5

Approach: Given parallel sides and height of trapezium. 

Formula: Area is 1/2*(sum of parallel side)*height.

Java

public class AreaofTrapezium {

    public static void main(String[] args) {
        double parallelside1 = 4;
        double parallelside2 = 5;
        double height = 3;
        double area = areaTrapezium(parallelside1, parallelside2, height);
        System.out.println("Area of Trapezium is " + area);
    }

    private static double areaTrapezium(double parallelside1
double parallelside2double height) {
        return ((parallelside1+parallelside2)*height)/2;
    }

}

C++

#include <bits/stdc++.h>
using namespace std;
//function to find the area
//of trapezium
double areaTrapezium(double parallelside1,double parallelside2,double height)
{
    double area=((parallelside1+parallelside2)*height)/2;
    return area;
}
int main()
{
    double parallelside1=4;
    double parallelside2=5;
    double height=3;
    double area=areaTrapezium(parallelside1,parallelside2,height);
    cout<<"Area of Trapezium is ";
    cout<<area<<"\n";
    return 0;
}


No comments:

Post a Comment