Area of a triangle inside a parallelogram
Last Updated :
02 Jul, 2022
Given the base and height of the parallelogram ABCD are b and h respectively. The task is to calculate the area of the triangle â–²ABM (M can be any point on upper side) constructed on the base AB of the parallelogram as shown below:
Examples:
Input: b = 30, h = 40
Output: 600.000000
Approach:
Area of a triangle constructed on the base of parallelogram and touching at any point on the opposite parallel side of the parallelogram can be given as = 0.5 * base * height
Hence, Area of â–²ABM = 0.5 * b * h
Below is the implementation of the above approach:
C++
#include <iostream>
using namespace std;
float CalArea( float b, float h)
{
return (0.5 * b * h);
}
int main()
{
float b, h, Area;
b = 30;
h = 40;
Area = CalArea(b, h);
cout << "Area of Triangle is :" << Area;
return 0;
}
|
C
#include <stdio.h>
float CalArea( float b, float h)
{
return (0.5 * b * h);
}
int main()
{
float b, h, Area;
b = 30;
h = 40;
Area = CalArea(b, h);
printf ( "Area of Triangle is : %f\n" , Area);
return 0;
}
|
Java
public class parallelogram {
public static void main(String args[])
{
double b = 30 ;
double h = 40 ;
double area_triangle = 0.5 * b * h;
System.out.println( "Area of the Triangle = " + area_triangle);
}
}
|
Python
b = 30
h = 40
area_triangle = 0.5 * b * h
print ( "Area of the triangle = " + str (area_triangle))
|
C#
using System;
class parallelogram {
public static void Main()
{
double b = 30;
double h = 40;
double area_triangle = 0.5 * b * h;
Console.WriteLine( "Area of the triangle = " + area_triangle);
}
}
|
PHP
<?php
$b = 30;
$h = 40;
$area_triangle =0.5* $b * $h ;
echo "Area of the triangle = " ;
echo $area_triangle ;
?>
|
Javascript
<script>
var b = 30;
var h = 40;
var area_triangle = 0.5 * b * h;
document.write( "Area of the Triangle = " + area_triangle.toFixed(6));
</script>
|
Output:
Area of triangle is : 600.000000
Time complexity: O(1), since there is no loop or recursion.
Auxiliary Space: O(1), since no extra space has been taken.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...