📜  计算风筝面积的程序

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

风筝有点像菱形,但在风筝中,相邻的边相等,对角线通常不相等。

方法一:当两条对角线都给定时

如果给定风筝的对角线d1d2 ,则风筝的面积是两条对角线乘积的一半,即

\ Area = \frac{ d1 * d2 } {2} \

例子:

Input: d1 = 4, d2 = 6
Output: Area of Kite  = 12

Input: d1 = 5, d2 = 7
Output: Area of Kite  = 17.5

方法:在这种方法中,我们简单地使用上面的公式。
下面是上述方法的实现:

C++
// C++ implementation of the approach
  
#include 
using namespace std;
  
// Function to return the area of kite
float areaOfKite(int d1, int d2)
{
    // use above formula
    float area = (d1 * d2) / 2;
    return area;
}
  
// Driver code
int main()
{
    int d1 = 4, d2 = 6;
    cout << "Area of Kite = "
         << areaOfKite(d1, d2);
  
    return 0;
}


Java
// Java implementation of the approach
class GFG 
{
  
    // Function to return the area of kite
    static float areaOfKite(int d1, int d2)
    {
        // Use above formula
        float area = (d1 * d2) / 2;
        return area;
    }
  
    // Driver code
    public static void main(String[] args)
    {
        int d1 = 4, d2 = 6;
        System.out.println("Area of Kite = "
                + areaOfKite(d1, d2));
    }
}
  
// This code is contributed by Rajput-Ji


Python3
# Python implementation of the approach
  
# Function to return the area of kite
def areaOfKite(d1, d2):
  
    # use above formula
    area = (d1 * d2) / 2;
    return area;
  
# Driver code
d1 = 4;
d2 = 6;
print("Area of Kite = ",
    areaOfKite(d1, d2));
  
# This code is contributed by Rajput-Ji


C#
// C# implementation of the approach
using System;
  
class GFG 
{
  
// Function to return the area of kite
static float areaOfKite(int d1, int d2)
{
    // Use above formula
    float area = (d1 * d2) / 2;
    return area;
}
  
// Driver code
public static void Main()
{
    int d1 = 4, d2 = 6;
    Console.WriteLine("Area of Kite = "
            + areaOfKite(d1, d2));
}
}
  
// This code is contributed by anuj_67..


Javascript


C++
// C++ implementation of the approach
  
#include 
#define PI 3.14159 / 180
using namespace std;
  
// Function to return the area of the kite
float areaOfKite(int a, int b, double angle)
{
    // convert angle degree to radians
    angle = angle * PI;
    // use above formula
  
    double area = a * b * sin(angle);
    return area;
}
  
// Driver code
int main()
{
    int a = 4, b = 7, angle = 78;
    cout << "Area of Kite = "
         << areaOfKite(a, b, angle);
  
    return 0;
}


Java
// Java implementation of the approach
import java.io.*;
  
class GFG
{
      
static double PI = (3.14159 / 180);
  
// Function to return the area of the kite
static float areaOfKite(int a, int b, double angle)
{
    // convert angle degree to radians
    angle = angle * PI;
      
    // use above formula
    double area = a * b * Math.sin(angle);
    return (float)area;
}
  
// Driver code
public static void main (String[] args)
{
  
    int a = 4, b = 7, angle = 78;
    System.out.println ("Area of Kite = " + areaOfKite(a, b, angle));
}
}
  
// This code is contributed by jit_t.


Python3
# Python implementation of the approach
import math
PI = 3.14159 / 180;
  
# Function to return the area of the kite
def areaOfKite(a, b, angle):
      
    # convert angle degree to radians
    angle = angle * PI;
      
    # use above formula
  
    area = a * b * math.sin(angle);
    return area;
  
# Driver code
a = 4; b = 7; angle = 78;
print("Area of Kite = ",
        areaOfKite(a, b, angle));
  
# This code contributed by PrinciRaj1992


C#
// C# implementation of the approach
using System;
  
class GFG
{
    static double PI = (3.14159 / 180);
  
// Function to return the area of the kite
static float areaOfKite(int a, int b, double angle)
{
    // convert angle degree to radians
    angle = angle * PI;
      
    // use above formula
    double area = a * b * Math.Sin(angle);
    return (float)area;
}
  
// Driver code
static public void Main ()
{
    int a = 4, b = 7, angle = 78;
    Console.WriteLine("Area of Kite = " + areaOfKite(a, b, angle));
}
}
  
// This code is contributed by ajit


Javascript


输出:

Area of Kite = 12

方法二:当给定边a、b和角度时:

当风筝ab的不等边和它们之间的夹角θ给定时,则

\ Area = a*b*sin\theta \

例子:

Input: a = 4, b = 7, θ = 78
Output: Area of Kite  = 27.3881

Input: a = 6, b = 9, θ = 83
Output: Area of Kite  = 53.5975

方法:在这种方法中,我们简单地使用上面的公式。
下面是上述方法的实现:

C++

// C++ implementation of the approach
  
#include 
#define PI 3.14159 / 180
using namespace std;
  
// Function to return the area of the kite
float areaOfKite(int a, int b, double angle)
{
    // convert angle degree to radians
    angle = angle * PI;
    // use above formula
  
    double area = a * b * sin(angle);
    return area;
}
  
// Driver code
int main()
{
    int a = 4, b = 7, angle = 78;
    cout << "Area of Kite = "
         << areaOfKite(a, b, angle);
  
    return 0;
}

Java

// Java implementation of the approach
import java.io.*;
  
class GFG
{
      
static double PI = (3.14159 / 180);
  
// Function to return the area of the kite
static float areaOfKite(int a, int b, double angle)
{
    // convert angle degree to radians
    angle = angle * PI;
      
    // use above formula
    double area = a * b * Math.sin(angle);
    return (float)area;
}
  
// Driver code
public static void main (String[] args)
{
  
    int a = 4, b = 7, angle = 78;
    System.out.println ("Area of Kite = " + areaOfKite(a, b, angle));
}
}
  
// This code is contributed by jit_t.

蟒蛇3

# Python implementation of the approach
import math
PI = 3.14159 / 180;
  
# Function to return the area of the kite
def areaOfKite(a, b, angle):
      
    # convert angle degree to radians
    angle = angle * PI;
      
    # use above formula
  
    area = a * b * math.sin(angle);
    return area;
  
# Driver code
a = 4; b = 7; angle = 78;
print("Area of Kite = ",
        areaOfKite(a, b, angle));
  
# This code contributed by PrinciRaj1992

C#

// C# implementation of the approach
using System;
  
class GFG
{
    static double PI = (3.14159 / 180);
  
// Function to return the area of the kite
static float areaOfKite(int a, int b, double angle)
{
    // convert angle degree to radians
    angle = angle * PI;
      
    // use above formula
    double area = a * b * Math.Sin(angle);
    return (float)area;
}
  
// Driver code
static public void Main ()
{
    int a = 4, b = 7, angle = 78;
    Console.WriteLine("Area of Kite = " + areaOfKite(a, b, angle));
}
}
  
// This code is contributed by ajit

Javascript


输出:
Area of Kite = 27.3881

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