Find the altitude and area of an isosceles triangle in C++

C++Server Side ProgrammingProgramming

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

 Live Demo

#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
raja
Published on 19-Dec-2019 15:27:39
Advertisements