- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find the altitude and area of an isosceles triangle in C++
Consider we have the side of the isosceles triangle, our task is to find the area of it and the altitude. In this type of triangle, two sides are equal. Suppose the sides of the triangle are 2, 2 and 3, then altitude is 1.32 and the area is 1.98.
Altitude(h)=$$\sqrt{a^{2}-\frac{b^{2}}{2}}$$
Area(A)=$\frac{1}{2}*b*h$
Example
#include<iostream> #include<cmath> using namespace std; float getAltitude(float a, float b) { return sqrt(pow(a, 2) - (pow(b, 2) / 4)); } float getArea(float b, float h) { return (1 * b * h) / 2; } int main() { float a = 2, b = 3; cout << "Altitude: " << getAltitude(a, b) << ", Area: " << getArea(b, getAltitude(a, b)); }
Output
Altitude: 1.32288, Area: 1.98431
Advertisements