Area of a triangle inside a parallelogram

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 * hBelow is the implementation of the above approach: 
C++
C
Java
Python
C#
PHP
Javascript
#include <iostream>using namespace std; // function to calculate the areafloat CalArea(float b, float h){    return (0.5 * b * h);}// driver codeint main(){    float b, h, Area;    b = 30;    h = 40;     // function calling    Area = CalArea(b, h);    // displaying the area    cout << "Area of Triangle is :" << Area;    return 0;}
#include <stdio.h> // function to calculate the areafloat CalArea(float b, float h){    return (0.5 * b * h);} // driver codeint main(){    float b, h, Area;    b = 30;    h = 40;     // function calling    Area = CalArea(b, h);     // displaying the area    printf("Area of Triangle is : %f\n", Area);    return 0;}
public class parallelogram {    public static void main(String args[])    {        double b = 30;        double h = 40;         // formula for calculating the area        double area_triangle = 0.5 * b * h;         // displaying the area        System.out.println("Area of the Triangle = " + area_triangle);    }}
b = 30h = 40  # formula for finding the areaarea_triangle = 0.5 * b * h # displaying the outputprint("Area of the triangle = "+str(area_triangle))
using System;class parallelogram {    public static void Main()    {        double b = 30;        double h = 40;         // formula for calculating the area        double area_triangle = 0.5 * b * h;         // displaying the area        Console.WriteLine("Area of the triangle = " + area_triangle);    }}
<?php      $b = 30;    $h = 40;    $area_triangle=0.5*$b*$h;     echo "Area of the triangle = ";     echo $area_triangle; ?>
<script>    var b = 30;    var h = 40;     // formula for calculating the area    var area_triangle = 0.5 * b * h;     // displaying the area    document.write("Area of the Triangle = " + area_triangle.toFixed(6)); // This code is contributed by Rajput-Ji</script>
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.
Rajput-Ji
hasani
subham348
area-volume-programs
Geometric
Mathematical
Mathematical
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Rotation of a point about another point in C++
Maximum Manhattan distance between a distinct pair from N coordinates
C++ Program to Illustrate Trigonometric functions
Total area of two overlapping rectangles
Largest area possible after removal of a series of horizontal & vertical bars
Program for Fibonacci numbers
Set in C++ Standard Template Library (STL)
Write a program to print all permutations of a given string
C++ Data Types
Merge two sorted arrays