Circunradio del rectángulo

Aquí tenemos un rectángulo de largo l y ancho b . Tenemos que encontrar el circunradio del rectángulo.

Ejemplos: 

Input : l = 3, b = 4 
Output :2.5

Input :l = 10, b = 12
Output :3.95227774224

Enfoque
del diagrama, podemos entender claramente que el circunradio r es la mitad de la diagonal del rectángulo. 

r = √(l^2 + b^2)/2

A continuación se muestra la implementación del enfoque anterior

C++

// C++ Program to find the radius
// of the circumcircle of the given rectangle
 
#include <bits/stdc++.h>
using namespace std;
 
// Function to find the radius
// of the circumcircle
float findRadiusOfcircumcircle(float l, float b)
{
 
    // the sides cannot be negative
    if (l < 0 || b < 0)
        return -1;
 
    // Radius of the circumcircle
    float radius = sqrt(pow(l, 2) + pow(b, 2)) / 2;
 
    // Return the radius
    return radius;
}
 
// Driver code
int main()
{
 
    // Get the sides of the triangle
    float l = 4, b = 3;
    // Find the radius of the circumcircle
    cout << findRadiusOfcircumcircle(l, b) << endl;
 
    return 0;
}

C

// C Program to find the radius
// of the circumcircle of the given rectangle
#include <stdio.h>
#include <math.h>
 
// Function to find the radius
// of the circumcircle
float findRadiusOfcircumcircle(float l, float b)
{
   
    // the sides cannot be negative
    if (l < 0 || b < 0)
        return -1;
   
    // Radius of the circumcircle
    float radius = sqrt(pow(l, 2) + pow(b, 2)) / 2;
  
    // Return the radius
    return radius;
}
  
// Driver code
int main()
{
   
    // Get the sides of the triangle
    float l = 4, b = 3;
   
    // Find the radius of the circumcircle
    printf("%f\n",findRadiusOfcircumcircle(l, b));
    return 0;
}

Java

// Java Program to find the radius
// of the circumcircle of the given
// rectangle
import java.util.*;
import java.lang.*;
import java.io.*;
 
class GFG
{
 
// Function to find the radius
// of the circumcircle
static float findRadiusOfcircumcircle(float l,
                                      float b)
{
 
    // the sides cannot be negative
    if (l < 0 || b < 0)
        return -1;
 
    // Radius of the circumcircle
    float radius = (float) Math.sqrt(Math.pow(l, 2) +
                           Math.pow(b, 2)) / 2;
 
    // Return the radius
    return radius;
}
 
// Driver code
public static void main(String args[])
{
 
    // Get the sides of the triangle
    float l = 4, b = 3;
    // Find the radius of the circumcircle
    System.out.println(findRadiusOfcircumcircle(l, b));
}
}
 
// This code is contributed by Subhadeep

Python3

# Python Program to find the
# radius of the circumcircle
# of the given rectangle
import math
 
# Function to find the radius
# of the circumcircle
def findRadiusOfcircumcircle(l, b):
 
    # the sides cannot be negative
    if (l < 0 or b < 0):
        return -1;
 
    # Radius of the circumcircle
    radius = (math.sqrt(pow(l, 2) +
                        pow(b, 2)) / 2);
 
    # Return the radius
    return radius;
 
# Driver code
 
# Get the sides of the triangle
l = 4;
b = 3;
     
# Find the radius of the circumcircle
print(findRadiusOfcircumcircle(l, b));
 
# This code is contributed
# by Shivi_Aggarwal

C#

// C# Program to find the radius
// of the circumcircle of the
// given rectangle
using System;
 
class GFG
{
 
// Function to find the radius
// of the circumcircle
static float findRadiusOfcircumcircle(float l,
                                       float b)
{
 
    // the sides cannot be negative
    if (l < 0 || b < 0)
        return -1;
 
    // Radius of the circumcircle
    float radius = (float) Math.Sqrt(Math.Pow(l, 2) +
                           Math.Pow(b, 2)) / 2;
 
    // Return the radius
    return radius;
}
 
// Driver code
public static void Main()
{
 
    // Get the sides of the triangle
    float l = 4, b = 3;
     
    // Find the radius of the circumcircle
    Console.WriteLine(findRadiusOfcircumcircle(l, b));
}
}
 
// This code is contributed by anuj_67

PHP

<?php
// PHP Program to find the radius
// of the circumcircle of the
// given rectangle
 
// Function to find the radius
// of the circumcircle
function findRadiusOfcircumcircle($l, $b)
{
 
    // the sides cannot be negative
    if ($l < 0 || $b < 0)
        return -1;
 
    // Radius of the circumcircle
    $radius = sqrt(pow($l, 2) +
                   pow($b, 2)) / 2;
 
    // Return the radius
    return $radius;
}
 
// Driver code
 
// Get the sides of the triangle
$l = 4; $b = 3;
 
// Find the radius of the circumcircle
echo findRadiusOfcircumcircle($l, $b);
 
// This code is contributed by anuj_67
?>

Javascript

<script>
 
// javascript Program to find the radius
// of the circumcircle of the given
// rectangle
 
// Function to find the radius
// of the circumcircle
function findRadiusOfcircumcircle(l,b)
{
 
    // the sides cannot be negative
    if (l < 0 || b < 0)
        return -1;
 
    // Radius of the circumcircle
    var radius = Math.sqrt(Math.pow(l, 2) +
                           Math.pow(b, 2)) / 2;
 
    // Return the radius
    return radius;
}
 
// Driver code
 
 
// Get the sides of the triangle
var l = 4, b = 3;
// Find the radius of the circumcircle
document.write(findRadiusOfcircumcircle(l, b).toFixed(6));
 
// This code contributed by shikhasingrajput
 
</script>

Producción: 

2.5

Complejidad de 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 *