Skip to content
Related Articles

Related Articles

Find the height of a right-angled triangle whose area is X times its base
  • Difficulty Level : Basic
  • Last Updated : 18 Jul, 2019

Given that the area of a right-angled triangle is X times its base b. The task is to find the height of the given triangle.
triangle

Examples:

Input: X = 40
Output: 80

Input: X = 100
Output: 200

Approach: We know that the area of a right-angled triangle, Area = (base * height) / 2 and it is given that this area is X times the base i.e. base * X = (base * height) / 2.
Solving for height, we get height = (2 * base * X) / base = 2 * X.



Below is the implementation of the above approach:

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ implementation of the approach
#include <bits/stdc++.h>
using namespace std;
  
// Function to return the height of the
// right-angled triangle whose area
// is X times its base
int getHeight(int X)
{
    return (2 * X);
}
  
// Driver code
int main()
{
    int X = 35;
  
    cout << getHeight(X);
  
    return 0;
}

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java implementation of the approach
import java.util.*;
import java.lang.*;
import java.io.*;
  
class Gfg
{
      
// Function to return the height of the
// right-angled triangle whose area
// is X times its base
static int getHeight(int X)
{
    return (2 * X);
}
  
// Driver code
public static void main (String[] args) throws java.lang.Exception
{
    int X = 35;
    System.out.println(getHeight(X)) ;
}
}
  
// This code is contributed by nidhiva

chevron_right


Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python 3 implementation of the approach
  
# Function to return the height of the
# right-angled triangle whose area
# is X times its base
def getHeight(X):
    return (2 * X)
  
# Driver code
if __name__ == '__main__':
    X = 35
  
    print(getHeight(X))
  
# This code is contributed by
# Surendra_Gangwar

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# implementation of the approach
using System;
  
class Gfg
{
      
// Function to return the height of the
// right-angled triangle whose area
// is X times its base
static int getHeight(int X)
{
    return (2 * X);
}
  
// Driver code
public static void Main () 
{
    int X = 35;
    Console.WriteLine(getHeight(X)) ;
}
}
  
// This code is contributed by anuj_67..

chevron_right


Output:

70

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :