Área del rombo más grande posible que se puede inscribir en un rectángulo

Dado un rectángulo de largo l y ancho b , la tarea es encontrar el rombo más grande que se puede inscribir en el rectángulo.
Ejemplos
 

Input : l = 5, b = 4
Output : 10

Input : l = 16, b = 6
Output : 48

De la figura, podemos ver, el rombo más grande que podría inscribirse dentro del rectángulo tendrá sus diagonales iguales a la longitud y la anchura del rectángulo. 
Entonces, Área del rombo, A = (l*b)/2
A continuación se muestra la implementación del enfoque anterior: 
 

C++

// C++ Program to find the biggest rhombus
// which can be inscribed within the rectangle
#include <bits/stdc++.h>
using namespace std;
 
// Function to find the area
// of the biggest rhombus
float rhombusarea(float l, float b)
{
    // the length and breadth cannot be negative
    if (l < 0 || b < 0)
        return -1;
 
    // area of the rhombus
    return (l * b) / 2;
}
 
// Driver code
int main()
{
    float l = 16, b = 6;
    cout << rhombusarea(l, b) << endl;
    return 0;
}

Java

// Java Program to find the
// biggest rhombus which can be
// inscribed within the rectangle
import java.io.*;
 
class GFG
{
 
// Function to find the area
// of the biggest rhombus
static float rhombusarea(float l,
                         float b)
{
    // the length and breadth
    // cannot be negative
    if (l < 0 || b < 0)
        return -1;
 
    // area of the rhombus
    return (l * b) / 2;
}
 
// Driver code
public static void main (String[] args)
{
    float l = 16, b = 6;
    System.out.println(rhombusarea(l, b));
}
}
 
// This code is contributed
// by inder_verma

Python3

# Python 3 Program to find the biggest rhombus
# which can be inscribed within the rectangle
 
 
# Function to find the area
# of the biggest rhombus
def rhombusarea(l,b):
    # the length and breadth cannot be negative
    if (l < 0 or b < 0):
        return -1
 
    # area of the rhombus
    return (l * b) / 2
 
# Driver code
if __name__ == '__main__':
    l = 16
    b = 6
    print(rhombusarea(l, b))

C#

// C# Program to find the
// biggest rhombus which can be
// inscribed within the rectangle
using System;
 
class GFG
{
 
// Function to find the area
// of the biggest rhombus
static float rhombusarea(float l,
                        float b)
{
    // the length and breadth
    // cannot be negative
    if (l < 0 || b < 0)
        return -1;
 
    // area of the rhombus
    return (l * b) / 2;
}
 
// Driver code
public static void Main ()
{
    float l = 16, b = 6;
    Console.WriteLine(rhombusarea(l, b));
}
}
 
// This code is contributed
// by shs

PHP

<?php
// PHP Program to find the
// biggest rhombus which can be
// inscribed within the rectangle
 
// Function to find the area
// of the biggest rhombus
function rhombusarea($l, $b)
{
    // the length and breadth
    // cannot be negative
    if ($l < 0 || $b < 0)
        return -1;
 
    // area of the rhombus
    return ($l * $b) / 2;
}
 
// Driver code
$l = 16; $b = 6;
echo rhombusarea($l, $b) . "\n";
 
// This code is contributed
// by Akanksha Rai(Abby_akku)

Javascript

<script>
 
// javascript Program to find the
// biggest rhombus which can be
// inscribed within the rectangle
 
// Function to find the area
// of the biggest rhombus
function rhombusarea(l,b)
{
    // the length and breadth
    // cannot be negative
    if (l < 0 || b < 0)
        return -1;
 
    // area of the rhombus
    return (l * b) / 2;
}
 
// Driver code
var l = 16, b = 6;
document.write(rhombusarea(l, b));
 
// This code contributed by Princi Singh
 
</script>
Producción: 

48

 

Complejidad del tiempo: O(1)

Espacio Auxiliar: O(1)

Publicación traducida automáticamente

Artículo escrito por IshwarGupta y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *