Javascript required
Skip to content Skip to sidebar Skip to footer

How to Find the Height of an Isosceles Triangle

Find the altitude and area of an isosceles triangle

Given the side (a) of the isosceles triangle. The task is to find the area (A) and the altitude (h). An isosceles triangle is a triangle with 2 sides of equal length and 2 equal internal angles adjacent to each equal sides.

Attention reader! Don't stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course .

In case you wish to attend live classes with experts, please refer DSA Live Classes for Working Professionals and Competitive Programming Live for Students.

In this figure,
a- Measure of the equal sides of an isosceles triangle.
b- Base of the isosceles triangle.
h- Altitude of the isosceles triangle.


Examples:

Input: a = 2, b = 3 Output: altitude = 1.32, area = 1.98  Input: a = 5, b = 6 Output: altitude = 4, area = 12

Formulas: Following are the formulas of the altitude and the area of an isosceles triangle.

Altitude (h)= \sqrt{a^{2}- \frac{b^{2}}{2}}     [Tex]Area (A)= \frac{1}{2} \times b \times h     [/Tex]

Below is the implementation using the above formulas:

C++

#include <bits/stdc++.h>

using namespace std;

float altitude( float a, float b)

{

return sqrt ( pow (a, 2) - ( pow (b, 2) / 4));

}

float area( float b, float h)

{

return (1 * b * h) / 2;

}

int main()

{

float a = 2, b = 3;

float h = altitude(a, b);

cout << setprecision(3);

cout << "Altitude= " << h << ", " ;

cout << "Area= " << area(b, h);

return 0;

}

Java

import java.io.*;

class GFG {

static float altitude( float a, float b)

{

return ( float )(Math.sqrt(Math.pow(a, 2 )

- (Math.pow(b, 2 ) / 4 )));

}

static float area( float b, float h)

{

return ( 1 * b * h) / 2 ;

}

public static void main(String[] args)

{

float a = 2 , b = 3 ;

float h = altitude(a, b);

System.out.print( "Altitude= " + h + ", " );

System.out.print( "Area= " + area(b, h));

}

}

Python 3

import math

def altitude(a, b):

return math.sqrt( pow (a, 2 ) -

( pow (b, 2 ) / 4 ))

def area(b, h):

return ( 1 * b * h) / 2

if __name__ = = "__main__" :

a = 2

b = 3

h = altitude(a, b)

print ( "Altitude = " +

str ( round (h, 3 )), end = ", " )

print ( "Area = " +

str ( round (area(b, h), 3 )))

C#

using System;

class GFG {

static float altitude( float a, float b)

{

return ( float )(Math.Sqrt(Math.Pow(a, 2)

- (Math.Pow(b, 2) / 4)));

}

static float area( float b, float h)

{

return (1 * b * h) / 2;

}

public static void Main()

{

float a = 2, b = 3;

float h = altitude(a, b);

Console.WriteLine( "Altitude = " + h + ", " );

Console.WriteLine( "Area = " + area(b, h));

}

}

PHP

<?php

function altitude( $a , $b )

{

return sqrt(pow( $a , 2) -

(pow( $b , 2) / 4));

}

function area( $b , $h )

{

return (1 * $b * $h ) / 2;

}

$a = 2; $b = 3;

$h = altitude( $a , $b );

echo "Altitude = " , $h , ", " ;

echo "Area = " , area( $b , $h );

?>

Javascript

<script>

function altitude(a,b)

{

return Math.sqrt(Math.pow(a, 2) - (Math.pow(b, 2) / 4));

}

function area( b, h)

{

return (1 * b * h) / 2;

}

let a = 2, b = 3;

let h = altitude(a, b);

document.write( "Altitude= " + h.toFixed(2) + ", " );

document.write( "Area= " + area(b, h).toFixed(2));

</script>

Output

Altitude= 1.32, Area= 1.98

Time Complexity: O(log n)
Auxiliary Space: O(1)


How to Find the Height of an Isosceles Triangle

Source: https://www.geeksforgeeks.org/find-the-altitude-and-area-of-an-isosceles-triangle/