📜  查找给定循环四边形的每一侧的内角

📅  最后修改于: 2021-04-17 17:53:54             🧑  作者: Mango

给定代表循环四边形边的四个正整数ABCD ,任务是找到循环四边形的所有内角。

例子:

方法:可以通过使用公式计算循环四边形的内角的余弦值来解决给定的问题。该公式由下式给出:

请按照以下步骤解决问题:

  • 存储循环四边形的每个内角的余弦值。
  • 使用acos()函数找到以弧度为单位的角度。
  • 将以弧度为单位的角度转换为度并打印结果。

下面是上述方法的实现:

C++
// C++ program for the above approach
#include 
using namespace std;
 
// Function to find the interior angles
// of the cyclic quadrilateral
void findAngles(double a, double b,
                double c, double d)
{
    // Stores the numerator and the
    // denominator to find angle A
    double numerator = a * a + d * d
                       - b * b - c * c;
 
    double denominator = 2 * (a * b + c * d);
 
    double x = numerator / denominator;
 
    cout << fixed << setprecision(2)
         << "A: " << (acos(x) * 180) / 3.141592
         << " degrees";
 
    // Stores the numerator and the
    // denominator to find angle B
    numerator = a * a + b * b
                - c * c - d * d;
 
    x = numerator / denominator;
 
    cout << fixed << setprecision(2)
         << "\nB: " << (acos(x) * 180) / 3.141592
         << " degrees";
 
    // Stores the numerator and the
    // denominator to find angle C:
    numerator = c * c + b * b
                - a * a - d * d;
 
    x = numerator / denominator;
 
    cout << fixed << setprecision(2)
         << "\nC: " << (acos(x) * 180) / 3.141592
         << " degrees";
 
    // Stores the numerator and the
    // denominator to find angle D:
    numerator = d * d + c * c
                - a * a - b * b;
 
    x = numerator / denominator;
 
    cout << fixed << setprecision(2)
         << "\nD: " << (acos(x) * 180) / 3.141592
         << " degrees";
}
 
// Driver Code
int main()
{
    double A = 10, B = 15, C = 20, D = 25;
    findAngles(A, B, C, D);
 
    return 0;
}


Java
// Java program for the above approach
class GFG{
     
// Function to find the interior angles
// of the cyclic quadrilateral
static void findAngles(double a, double b,
                       double c, double d)
{
     
    // Stores the numerator and the
    // denominator to find angle A
    double numerator = a * a + d * d -
                       b * b - c * c;
 
    double denominator = 2 * (a * b + c * d);
 
    double x = numerator / denominator;
 
    System.out.println("A: " +
       Math.round(((Math.acos(x) * 180) /
                       3.141592) * 100.0) /
                       100.0 + " degrees");
 
    // Stores the numerator and the
    // denominator to find angle B
    numerator = a * a + b * b - c * c - d * d;
 
    x = numerator / denominator;
 
    System.out.println("B: " +
       Math.round(((Math.acos(x) * 180) /
                       3.141592) * 100.0) /
                       100.0 + " degrees");
 
    // Stores the numerator and the
    // denominator to find angle C:
    numerator = c * c + b * b -
                a * a - d * d;
 
    x = numerator / denominator;
 
    System.out.println("C: " +
       Math.round(((Math.acos(x) * 180) /
                       3.141592) * 100.0) /
                       100.0 + " degrees");
 
    // Stores the numerator and the
    // denominator to find angle D:
    numerator = d * d + c * c -
                a * a - b * b;
 
    x = numerator / denominator;
 
    System.out.println("D: " +
       Math.round(((Math.acos(x) * 180) /
                       3.141592) * 100.0) /
                       100.0 + " degrees");
}
 
// Driver Code
public static void main (String[] args)
{
    double A = 10, B = 15, C = 20, D = 25;
     
    findAngles(A, B, C, D);
}
}
 
// This code is contributed by AnkThon


Python3
# Python3 program for the above approach
import math
 
# Function to find the interior angles
# of the cyclic quadrilateral
def findAngles(a, b, c, d):
     
    # Stores the numerator and the
    # denominator to find angle A
    numerator = a * a + d * d - b * b - c * c
    denominator = 2 * (a * b + c * d)
    x = numerator / denominator
    print("A: ", '%.2f' % ((math.acos(x) * 180) /
          3.141592), " degrees")
     
    # Stores the numerator and the
    # denominator to find angle B
    numerator = a * a + b * b - c * c - d * d
    x = numerator / denominator
    print("B: ", '%.2f' % ((math.acos(x) * 180) /
          3.141592), " degrees")
     
    # Stores the numerator and the
    # denominator to find angle C:
    numerator = c * c + b * b - a * a - d * d
    x = numerator / denominator
    print("C: ", '%.2f' % ((math.acos(x) * 180) /
          3.141592), " degrees")
     
    # Stores the numerator and the
    # denominator to find angle D:
    numerator = d * d + c * c - a * a - b * b
    x = numerator / denominator
    print("D: ", '%.2f' % ((math.acos(x) * 180) /
          3.141592), " degrees")
     
# Driver Code
if __name__ == "__main__":
     
    A = 10
    B = 15
    C = 20
    D = 25
     
    findAngles(A, B, C, D)
 
# This code is contributed by ukasp


C#
// C# program for the above approach
using System;
 
class GFG{
     
// Function to find the interior angles
// of the cyclic quadrilateral
static void findAngles(double a, double b,
                       double c, double d)
{
     
    // Stores the numerator and the
    // denominator to find angle A
    double numerator = a * a + d * d -
                       b * b - c * c;
 
    double denominator = 2 * (a * b + c * d);
 
    double x = numerator / denominator;
 
    Console.WriteLine("A: " +
       Math.Round(((Math.Acos(x) * 180) /
                       3.141592) * 100.0) /
                       100.0 + " degrees");
 
    // Stores the numerator and the
    // denominator to find angle B
    numerator = a * a + b * b - c * c - d * d;
 
    x = numerator / denominator;
 
    Console.WriteLine("B: " +
       Math.Round(((Math.Acos(x) * 180) /
                       3.141592) * 100.0) /
                       100.0 + " degrees");
 
    // Stores the numerator and the
    // denominator to find angle C:
    numerator = c * c + b * b -
                a * a - d * d;
 
    x = numerator / denominator;
 
    Console.WriteLine("C: " +
       Math.Round(((Math.Acos(x) * 180) /
                       3.141592) * 100.0) /
                       100.0 + " degrees");
 
    // Stores the numerator and the
    // denominator to find angle D:
    numerator = d * d + c * c -
                a * a - b * b;
 
    x = numerator / denominator;
 
    Console.WriteLine("D: " +
       Math.Round(((Math.Acos(x) * 180) /
                       3.141592) * 100.0) /
                       100.0 + " degrees");
}
 
// Driver Code
public static void Main(string[] args)
{
    double A = 10, B = 15, C = 20, D = 25;
     
    findAngles(A, B, C, D);
}
}
 
// This code is contributed by AnkThon


输出:
A: 85.59 degrees
B: 122.58 degrees
C: 94.41 degrees
D: 57.42 degrees

时间复杂度: O(1)
辅助空间: O(1)