
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Maximum Area of Quadrilateral in C++
Problem statement
Given four sides of quadrilateral a, b, c, d, find the maximum area of the quadrilateral possible from the given sides.
Algorithm
We can use below Brahmagupta’s formula to solve this problem −
√(s-a)(s-b)(s-c)(s-d)
In above formula s is semi-perimeter. It is calculated as follows −
S = (a + b + c + d) / 2
Example
Let us now see an example −
#include <bits/stdc++.h> using namespace std; double getMaxArea(double a, double b, double c, double d) { double s = (a + b + c + d) / 2; double area = (s - a) * (s - b) * (s - c) * (s - d); return sqrt(area); } int main() { double a = 1, b = 2.5, c = 1.8, d = 2; cout << "Maximum area = " << getMaxArea(a, b, c, d) << endl; return 0; }
Output
Maximum area = 3.05
Advertisements