Dado un rectángulo de largo y ancho . La tarea es encontrar el área del triángulo más grande que se puede inscribir en él.
Ejemplos :
Input: L = 5, B = 4 Output: 10 Input: L = 3, B = 2 Output: 3
A partir de la figura, es claro que el triángulo más grande que se puede inscribir en el rectángulo, debe estar sobre la misma base y tiene elevación de altura entre los mismos lados paralelos del rectángulo.
Entonces, la base del triángulo = B
Altura del triángulo = L
Por lo tanto Área,
A = (L*B)/2
Nota : también debe quedar claro que si la base del triángulo = diagonal del rectángulo, el área del triángulo así obtenida = lb/2 como diagonal de un rectángulo lo divide en 2 triángulos de igual área.
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ Program to find the biggest triangle // which can be inscribed within the rectangle #include <bits/stdc++.h> using namespace std; // Function to find the area // of the triangle float trianglearea(float l, float b) { // a and b cannot be negative if (l < 0 || b < 0) return -1; // area of the triangle float area = (l * b) / 2; return area; } // Driver code int main() { float l = 5, b = 4; cout << trianglearea(l, b) << endl; return 0; }
Java
// Java Program to find the biggest triangle // which can be inscribed within the rectangle import java.util.*; class GFG { // Function to find the area // of the triangle static float trianglearea(float l, float b) { // a and b cannot be negative if (l < 0 || b < 0) return -1; // area of the triangle float area = (l * b) / 2; return area; } // Driver code public static void main(String args[]) { float l = 5, b = 4; System.out.println(trianglearea(l, b)); } }
Python3
# Python3 Program to find the # biggest triangle which can be # inscribed within the rectangle # Function to find the area # of the triangle def trianglearea(l, b) : # a and b cannot be negative if (l < 0 or b < 0) : return -1 # area of the triangle area = (l * b) / 2 return area # Driver code l = 5 b = 4 print(trianglearea(l, b)) # This code is contributed # by Yatin Gupta
C#
// C# Program to find the biggest // triangle which can be inscribed // within the rectangle using System; class GFG { // Function to find the area // of the triangle static float trianglearea(float l, float b) { // a and b cannot be negative if (l < 0 || b < 0) return -1; // area of the triangle float area = (l * b) / 2; return area; } // Driver code public static void Main() { float l = 5, b = 4; Console.WriteLine(trianglearea(l, b)); } } // This code is contributed // by inder_verma
PHP
<?php // PHP Program to find the biggest // triangle which can be inscribed // within the rectangle // Function to find the area // of the triangle function trianglearea($l, $b) { // a and b cannot be negative if ($l < 0 or $b < 0) return -1; // area of the triangle $area = ($l * $b) / 2; return $area; } // Driver code $l = 5; $b = 4; echo trianglearea($l, $b); // This code is contributed // by inder_verma ?>
Javascript
<script> // javascript Program to find the biggest triangle // which can be inscribed within the rectangle // Function to find the area // of the triangle function trianglearea( l, b) { // a and b cannot be negative if (l < 0 || b < 0) return -1; // area of the triangle let area = (l * b) / 2; return area; } // Driver code let l = 5, b = 4; document.write( trianglearea(l, b) ); // This code contributed by aashish1995 </script>
10
Publicación traducida automáticamente
Artículo escrito por IshwarGupta y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA