Minimum height of a triangle with given base and area - GeeksforGeeks

28 Nov, 2021
Given two integers a and b, find the smallest possible height such that a triangle of atleast area “a” and base “b” can be formed. 
Examples :  
Input : a = 2, b = 2
Output : Minimum height of triangle is 2

Explanation: 
Input : a = 8, b = 4
Output : Minimum height of triangle is 4
Minimum height of Triangle with base “b” and area “a” can be evaluated by having the knowledge of the relationship between the three. 
The relation between area, base and height is: area = (1/2) * base * heightSo height can be calculated as : height = (2 * area)/ baseMinimum height is the ceil of the height obtained using above formula.
 
C++
Java
Python
C#
PHP
Javascript
#include <bits/stdc++.h>using namespace std;// function to calculate minimum height of // triangleint minHeight(int base, int area){    return ceil((float)(2*area)/base);}  int main() {    int base = 4, area = 8;    cout << "Minimum height is "          << minHeight(base, area) << endl;          return 0;}
// Java code Minimum height of a // triangle with given base and area  class GFG {          // function to calculate minimum height of     // triangle    static double minHeight(double base, double area)    {        double d = (2 * area) / base;        return Math.ceil(d);    }          // Driver code    public static void main (String[] args)     {        double base = 4, area = 8;        System.out.println("Minimum height is "+                            minHeight(base, area));    }}// This code is contributed by Anant Agarwal.
# Python Program to find minimum height of triangleimport math  def minHeight(area,base):        return math.ceil((2*area)/base)  # Driver codearea = 8base = 4height = minHeight(area, base)print("Minimum height is %d" % (height))
// C# program to find minimum height of// a triangle with given base and areausing System;  public class GFG {      // function to calculate minimum    // height of triangle    static int minHeight(int b_ase, int area)    {        return (int)Math.Round((float)(2 * area) / b_ase);    }          // Driver function    static public void Main()    {        int b_ase = 4, area = 8;        Console.WriteLine("Minimum height is "                        + minHeight(b_ase, area));    }}  // This code is contributed by vt_m.
<?php  // function to calculate minimum  // height of trianglefunction minHeight($base, $area){    return ceil((2 * $area) / $base);}  // Driver Code$base = 4;$area = 8;echo "Minimum height is ",       minHeight($base, $area);        // This code is contributed by anuj_67.?>
<script>  // function to calculate minimum height of // trianglefunction minHeight( base,  area){    return Math.ceil((2*area)/base);}        let base = 4, area = 8;               document.write( "Minimum height is "          +minHeight(base, area));  // This code contributed by aashish1995   </script>
Output : 
Minimum height is 4
 
vt_m
aashish1995
triangle
Geometric
Technical Scripter
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Convex Hull using Divide and Conquer Algorithm
Equation of circle when three points on the circle are given
Circle and Lattice Points
Orientation of 3 ordered points
Program to find slope of a line
Program to find line passing through 2 Points
Check if a line touches or intersects a circle
Minimum Cost Polygon Triangulation
Minimum distance to the corner of a grid from source
Line Clipping | Set 2 (Cyrus Beck Algorithm)