Minimum height of a triangle with given base and area in C++
Description
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.
Example
If a = 16 and b = 4 then minimum height would be 8
Algorithm
Area of triangle can be calculate using below formula −
area = ½ * height * base
Using above formula, height can be calculated as −
height = (2 * area) / base
So Minimum height is the ceil() of the height obtained using above formula.
Example
#include <iostream>
#include <cmath>
using namespace std;
float minHeight(int area, int base) {
return ceil((2 * area) / base);
}
int main() {
int area = 16, base = 4;
cout << "Minimum height = " << minHeight(area, base) << endl;
return 0;
}
Output
When you compile and execute above program. It generates following output −
Minimum height = 8
Related Articles
- How To Find Minimum Height of the Triangle with Given Base and Area in Java?
- The base and the height of triangle is 25 cm and 3 cm. Find the area of the triangle.
- Find minimum area of rectangle with given set of coordinates in C++
- Minimum number of nodes in an AVL Tree with given height using C++.
- Find the missing elements of the following parallelograms based on the information provided.a) Area =121.5 m2, base =16.2m, height =?b) Area =395cm2, height =12.5 cm, base =?c) Area =351 m2, base =15.6 m, height =?d) Area 4440 cm2, height =74 cm, base =?
- Find the height of the triangle whose base length is $22 cm$ and area is $170.5 cm^2$.
- The total surface area of a cylinder with a diameter of base 5cm and height 30 cm will be?
- Find the curved surface area of a cone with base radius $5.25\ cm$ and slant height $10\ cm$.
- A triangle and a parallelogram have the same base and the same area. If the sides of triangle are 26 cm, 28 cm and 30 cm, and the parallelogram stands on the base 28 cm, find the height of the parallelogram.
- A triangle and a parallelogram have the same base and the same area. If the sides of the triangle are $13\ cm, 14\ cm$ and $15\ cm$ and the parallelogram stands on the base $14\ cm$, find the height of the parallelogram.
- Check if a triangle of positive area is possible with the given angles in Python
- Area of a triangle inside a parallelogram in C++
- Area of a polygon with given n ordered vertices in C++
- The perimeter of an isosceles triangle is $42\ cm$ and its base is ($\frac{3}{2}) times each of the equal sides. Find the length of each side of the triangle, area of the triangle and the height of the triangle.
Kickstart Your Career
Get certified by completing the course
Get Started