📜  平行四边形内的三角形面积

📅  最后修改于: 2021-05-06 17:44:17             🧑  作者: Mango

给定平行四边形的基数和高度ABCD分别为b和h 。任务是计算在平行四边形的基础AB上构造的三角形▲ABM的面积(M可以是上侧的任何点),如下所示:

例子:

Input: b = 30, h = 40
Output: 600.000000

方法:

因此, ▲ABM的面积= 0.5 * b * h
下面是上述方法的实现:

C++
#include 
using namespace std;
 
// function to calculate the area
float CalArea(float b, float h)
{
    return (0.5 * b * h);
}
// driver code
int main()
{
    float b, h, Area;
    b = 30;
    h = 40;
 
    // function calling
    Area = CalArea(b, h);
    // displaying the area
    cout << "Area of Triangle is :" << Area;
    return 0;
}


C
#include 
 
// function to calculate the area
float CalArea(float b, float h)
{
    return (0.5 * b * h);
}
 
// driver code
int main()
{
    float b, h, Area;
    b = 30;
    h = 40;
 
    // function calling
    Area = CalArea(b, h);
 
    // displaying the area
    printf("Area of Triangle is : %f\n", Area);
    return 0;
}


Java
public class parallelogram {
    public static void main(String args[])
    {
        double b = 30;
        double h = 40;
 
        // formula for calculating the area
        double area_triangle = 0.5 * b * h;
 
        // displaying the area
        System.out.println("Area of the Triangle = " + area_triangle);
    }
}


Python
b = 30
h = 40 
 
# formula for finding the area
area_triangle = 0.5 * b * h
 
# displaying the output
print("Area of the triangle = "+str(area_triangle))


C#
using System;
class parallelogram {
    public static void Main()
    {
        double b = 30;
        double h = 40;
 
        // formula for calculating the area
        double area_triangle = 0.5 * b * h;
 
        // displaying the area
        Console.WriteLine("Area of the triangle = " + area_triangle);
    }
}


PHP


Javascript


输出:
Area of triangle is : 600.000000