📌  相关文章
📜  内接于椭圆的矩形内接三角形的面积

📅  最后修改于: 2021-10-23 08:07:44             🧑  作者: Mango

这里给出的是一个轴长为2a2b的椭圆,它内接一个长lh的矩形,它又内接一个三角形。任务是找到这个三角形的面积。
例子:

Input: a = 4, b = 3
Output: 12

Input: a = 5, b = 2
Output: 10

方法
我们知道椭圆内切矩形的面积是, Ar = 2ab (请参考这里),
还有内接在矩形 s 内的三角形面积, A = Ar/2 = ab (请参阅此处)
下面是上述方法的实现

C++
// C++ Program to find the area of the triangle
// inscribed within the rectangle which in turn
// is inscribed in an ellipse
#include 
using namespace std;
 
// Function to find the area of the triangle
float area(float a, float b)
{
 
    // length of a and b cannot be negative
    if (a < 0 || b < 0)
        return -1;
 
    // area of the triangle
    float A = a * b;
    return A;
}
 
// Driver code
int main()
{
    float a = 5, b = 2;
    cout << area(a, b) << endl;
    return 0;
}


Java
// Java Program to find the area of the triangle
// inscribed within the rectangle which in turn
// is inscribed in an ellipse
 
import java.io.*;
 
class GFG {
 
// Function to find the area of the triangle
static float area(float a, float b)
{
 
    // length of a and b cannot be negative
    if (a < 0 || b < 0)
        return -1;
 
    // area of the triangle
    float A = a * b;
    return A;
}
 
// Driver code
 
 
    public static void main (String[] args) {
    float a = 5, b = 2;
    System.out.println(area(a, b));
    }
}
//This code is contributed by anuj_67..


Python3
# Python 3 Program to find the
# area of the triangle inscribed
# within the rectangle which in
# turn is inscribed in an ellipse
 
# Function to find the area
# of the triangle
def area(a, b):
     
    # length of a and b cannot
    # be negative
    if (a < 0 or b < 0):
        return -1
 
    # area of the triangle
    A = a * b
    return A
 
# Driver code
if __name__ == '__main__':
    a = 5
    b = 2
    print(area(a, b))
     
# This code is contributed
# by Surendra_Gangwar


C#
// C# Program to find the area of
// the triangle inscribed within
// the rectangle which in turn
// is inscribed in an ellipse
using System;
 
class GFG
{
     
// Function to find the
// area of the triangle
static float area(float a, float b)
{
 
    // length of a and b
    // cannot be negative
    if (a < 0 || b < 0)
        return -1;
 
    // area of the triangle
    float A = a * b;
    return A;
}
 
// Driver code
static public void Main ()
{
    float a = 5, b = 2;
    Console.WriteLine(area(a, b));
}
}
 
// This code is contributed by ajit


PHP


Javascript


输出:
10