Program to find the angles of a quadrilateral

16 Jun, 2022
Given that all the angles of a quadrilateral are in AP having common difference ‘d’, the task is to find all the angles.Examples:  
Input: d = 10
Output: 75, 85, 95, 105

Input: d = 20
Output: 60, 80, 100, 120
 
Approach: 
We know that the angles of the quadrilateral are in AP and having the common difference ‘d’. So, if we assume the first angle to be ‘a’ then the other angles can be calculated as, ‘a+d’, ‘a+2d’ and ‘a+3d’ And, from the properties of quadrilaterals, the sum of all the angles of a quadrilateral is 360. So, (a) + (a + d) + (a + 2*d) + (a + 3*d) = 360 4*a + 6*d = 360 a = (360 – (6*d)) / 4 where ‘a’ is the angle assumed in the beginning and ‘d’ is the common difference.  
Below is the implementation of the above approach:  
C++
Java
Python
C#
PHP
Javascript
// C++ implementation of the approach#include <bits/stdc++.h>#define ll long long intusing namespace std; // Driver codeint main(){    int d = 10;    double a;     // according to formula derived above    a = (double)(360 - (6 * d)) / 4;     // print all the angles    cout << a << ", " << a + d << ", " << a + (2 * d)         << ", " << a + (3 * d) << endl;    return 0;}
// java implementation of the approach import java.io.*; class GFG {  // Driver code     public static void main (String[] args) {            int d = 10;    double a;     // according to formula derived above    a = (double)(360 - (6 * d)) / 4;     // print all the angles    System.out.print( a + ", " + (a + d) + ", " + (a + (2 * d))        + ", " + (a + (3 * d)));    }}//This code is contributed//by  inder_verma
# Python implementation# of the approachd = 10a = 0.0 # according to formula# derived abovea=(360 - (6 * d)) / 4 # print all the anglesprint(a,",", a + d, ",", a + 2 * d,        ",", a + 3 * d, sep = ' ') # This code is contributed# by sahilshelangia
// C# implementation of the approachusing System; class GFG{ // Driver codepublic static void Main (){    int d = 10;    double a;         // according to formula derived above    a = (double)(360 - (6 * d)) / 4;         // print all the angles    Console.WriteLine( a + ", " + (a + d) +                           ", " + (a + (2 * d)) +                           ", " + (a + (3 * d)));}} // This code is contributed// by anuj_67
<?php// PHP implementation of the approach // Driver code$d = 10; // according to formula// derived above$a = (360 - (6 * $d)) / 4 ; // print all the anglesecho $a, ", ", $a + $d , ", ",     $a + (2 * $d), ", ", $a + (3 * $d); // This code is contributed// by ANKITRAI1?>
<script> // Javascript implementation of the approach // Driver codevar d = 10;var a; // according to formula derived abovea = parseInt((360 - (6 * d)) / 4); // print all the anglesdocument.write( a + ", " + (a + d) + ", " + (a + (2 * d))    + ", " + (a + (3 * d)));  </script>
Time complexity: O(1)
Auxiliary Space: O(1)
sahilshelangia
inderDuMCA
ankthon
vt_m
rutvik_56
hasani
arithmetic progression
Competitive Programming
Geometric
Mathematical
Mathematical
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Most important type of Algorithms
The Ultimate Beginner's Guide For DSA
Find two numbers from their sum and XOR
Equal Sum and XOR of three Numbers
C++: Methods of code shortening in competitive programming
Program for distance between two points on earth
Closest Pair of Points using Divide and Conquer algorithm
How to check if a given point lies inside or outside a polygon?
How to check if two given line segments intersect?
Optimum location of point to minimize total distance