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

📅  最后修改于: 2021-10-23 08:51:52             🧑  作者: 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

如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程学生竞争性编程现场课程