📜  查找梯形区域的程序

📅  最后修改于: 2021-04-23 20:40:49             🧑  作者: Mango

梯形的定义:
梯形是具有至少一对平行边的凸四边形。平行的边称为梯形的底,不平行的另外两个边称为支腿。也可以有两对碱基。

上图中的CD || AB,因此它们形成了底脚,另两个侧面(即AD和BC)形成了支脚。
梯形的面积可以通过以下简单公式求出:

Area=\frac{a+b}{2}h

a =基数
b =基数
h =高度
例子 :

Input : base1 = 8, base2 = 10, height = 6
Output : Area is: 54.0

Input :base1 = 4, base2 = 20, height = 7
Output :Area is: 84.0
C++
// C++ program to calculate
// area of a trapezoid
#include
using namespace std;
 
// Function for the area
double Area(int b1, int b2,
                    int h)
{
    return ((b1 + b2) / 2) * h;
}
 
// Driver Code
int main()
{
    int base1 = 8, base2 = 10,
                height = 6;
    double area = Area(base1, base2,
                            height);
    cout << "Area is: " << area;
    return 0;
}
 
// This code is contributed by shivanisinghss2110


C
// CPP program to calculate
// area of a trapezoid
#include 
 
// Function for the area
double Area(int b1, int b2,
                    int h)
{
    return ((b1 + b2) / 2) * h;
}
 
// Driver Code
int main()
{
    int base1 = 8, base2 = 10,
                   height = 6;
    double area = Area(base1, base2,
                              height);
    printf("Area is: %.1lf", area);
    return 0;
}


Java
// Java program to calculate
// area of a trapezoid
import java.io.*;
 
class GFG
{
     
    // Function for the area
    static double Area(int b1,
                       int b2,
                       int h)
    {
        return ((b1 + b2) / 2) * h;
    }
 
    // Driver Code
    public static void main (String[] args)
    {
        int base1 = 8, base2 = 10,
                       height = 6;
        double area = Area(base1, base2,
                                  height);
        System.out.println("Area is: " + area);
    }
}


Python3
# Python program to calculate
# area of a trapezoid
 
# Function for the area
def Area(b1, b2, h):
    return ((b1 + b2) / 2) * h
 
# Driver Code
base1 = 8; base2 = 10; height = 6
area = Area(base1, base2, height)
print("Area is:", area)


C#
// C# program to calculate
// area of a trapezoid
using System;
 
class GFG
{
     
    // Function for the area
    static double Area(int b1,
                       int b2,
                       int h)
    {
        return ((b1 + b2) / 2) * h;
    }
 
    // Driver Code
    public static void Main ()
    {
        int base1 = 8, base2 = 10,
                       height = 6;
        double area = Area(base1, base2,
                                  height);
        Console.WriteLine("Area is: " + area);
    }
}
 
// This code is contributed by vt_m


PHP


Javascript


输出 :

Area is: 54.0