Q:

Write a program to calculate the Altitude of Isosceles Triangle

belongs to collection: Miscellaneous Programs Examples

0

Before writing the program of calculating the altitude of isosceles triangle in different programming languages, firstly we have to know about the formula to find altitude of Isosceles triangle?

 

Altitude of Isosceles Triangle = sqrt (( a *a ) - (( b * b ) / 4) )  

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program of calculating the altitude of Isosceles Triangle in different Programming languages

Program 1: Write a Program in C language:

// This a C program which uses a function to find the altitude of a Isosceles Triangle.  
#include <stdio.h>  
float find_Altitude_of_Isosceles_Triangle(float a, float b) // It is a function to find altitude   
{   
float Altitude_of_Isosceles_Triangle;  
Altitude_of_Isosceles_Triangle= sqrt(( a *a ) - (( b * b ) / 4)); // It is a formula for calculating a altitude of Isosceles Triangle   
return (Altitude_of_Isosceles_Triangle);   
}   
int main()   
{   
float a, b;   
printf("Enter the side a of the Isosceles Triangle:");   
scanf("%f",&a);  
printf("Enter the base b of the Isosceles Triangle:");   
scanf("%f",&b);  
printf("Altitude of the Isosceles Triangle is: %.2f", find_Altitude_of_Isosceles_Triangle(a , b));     
return 0;   
}  

 

Output of Above C program:

Enter the side a of the Isosceles Triangle:5
Enter the base b of the Isosceles Triangle:8
Altitude of the Isosceles Triangle is: 3.00

 

Program 2: Write a Program in Java language:

// This a  Java program which calculates the altitude of a Isosceles Triangle.  
import java.lang.Math;  
class findaltitude {   
static double find_Altitude_of_Isosceles_Triangle (int a, int b)   
{   
double Altitude_of_Isosceles_Triangle;  
Altitude_of_Isosceles_Triangle= Math.sqrt(( a *a ) - (( b * b ) / 4));; // It is a formula for calculating the altitude of Isosceles Triangle   
return(Altitude_of_Isosceles_Triangle);   
}   
// Driver method   
public static void main(String[] args)   
{   
int a=5;   
int base=8;  
System.out.println("The Altitude of a Isosceles Triangle in Java:");  
System.out.println(find_Altitude_of_Isosceles_Triangle(a,base));   
}   
}  

 

Output of Above Java program:

The Altitude of a Isosceles Triangle in Java:
3.0

 

Program 3: Write a Program in PHP programming language.

<?php   
// This a  PHP program which calculates the altitude of a IsoscelesTriangle.    
// Function to find altitude   
function find_Altitude_of_Isosceles_Triangle($a, $b)   
{           
$Altitude_of_IsoscelesTriangle = sqrt(( $a * $a ) - (( $b * $b ) / 4));; // It is a formula which calculates the altitude  and store the value in the altitude variable.   
return ($Altitude_of_IsoscelesTriangle);   
}   
$a = 5.0;   
$b = 8.0;  
echo find_Altitude_of_Isosceles_Triangle($a,$b);   
?>  

 

Output of Above PHP program:

3

 

Program 4: Write a Program in Python programming language.

# This is a python program which calculates the altitude of a IsoscelesTriangle.   
# It is a function to calculate the altitude of Isosceles Triangle  
from math import sqrt  
def find_Altitude_of_Isosceles_Triangle(a,b):  
    return (sqrt(( a *a ) -(( b * b ) / 4))) # It is a formula which adds the three side and   
   then return the value to the statement calling fucntion.  
a=5  
base=8  
print(find_Altitude_of_Isosceles_Triangle(a, base))  

 

Output of Above Python program:

3.0

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Miscellaneous Programs Examples

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a Program to calculate the Area of Isosceles... >>
<< Write a Program to find the Perimeter of Ellipse...