假定直角三角形的面积是其底边b的X倍。任务是找到给定三角形的高度。
例子:
Input: X = 40
Output: 80
Input: X = 100
Output: 200
方法:我们知道一个直角三角形的面积Area =(基数*高度)/ 2 ,并且假定该面积是基数的X倍,即基数* X =(基数*高度)/ 2。
求解高度,我们得到height =(2 * base * X)/ base = 2 * X。
下面是上述方法的实现:
C++
// C++ implementation of the approach
#include
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;
}
Java
// 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
Python3
# 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
C#
// 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..
Javascript
输出:
70