Program to find the angles of a quadrilateral in C++

C++Server Side ProgrammingProgramming

In this problem, we are given a value d, which is the common difference of AP. This AP is all the angles of a quadrilateral. Our task is to create a program to find the angles of a quadrilateral in C++.

Problem Description − Here, the angles of the quadrilateral are in the form of an AP with common difference d. And we need to find the angles.

Let’s take an example to understand the problem

Input

d = 15

Output

67.5, 82.5, 97.5, 112.5

Explanation

First angle is x
Second angle is x + 15
Third angle is x + 30
Four angle is x + 45

Sum of angles of a quadrilateral is 360.

x + x + 15 + x + 30 + x + 45 = 360
4x + 90 = 360
4x = 270 => x = 67.5

Solution Approach

To solve this problem, we will use the properties of AP and quadrilateral.

We will take the 1st four angles of AP starting with x. They will be x, x+d, x+2d, x+3d.

The sum of all the angles of a quadrilateral is 360. Considering this

x + x+d + x+2d + x+3d = 360
4x + 6d = 360
2x + 3d = 180 => x = (180 - 3d)/2

Using this formula we will find the value of one angle of the quadrilateral as we know the value of d. We will be able to find all the rest angles too.

Program to illustrate the working of our solution

Example

 Live Demo

#include <iostream>
using namespace std;
float findAngle(float d){
   return ((180 - (3*d))/2);
}
int main(){
   float d = 25;
   float a = findAngle(d);
   cout<<"The angles of the quadrilateral are: "<<a<<"\t"<<(a+d)<<"\t"<<(a+ 2*d)<<"\t"   <<(a+3*d);
   return 0;
}

Output

The angles of the quadrilateral are: 52.5 77.5 102.5 127.5
raja
Published on 27-May-2020 09:48:09
Advertisements