Dado un círculo en el que se dan el ancho y la altura de un arco. La tarea es encontrar el radio del círculo con la ayuda del ancho y la altura del arco.
Ejemplos:
Input: d = 4, h = 1 Output: The radius of the circle is 2.5 Input: d = 14, h = 8 Output: The radius of the circle is 7.0625
Acercarse
- Sea el radio del círculo r
- Sean la altura y el ancho del arco h & d
- Ahora, el diámetro DC biseca la cuerda AB en dos mitades, cada una de longitud d/2
- También el diámetro se divide por la cuerda en dos partes, la parte interior del arco h y las restantes 2r-h
- Ahora, a partir del teorema de las cuerdas que se cruzan ,
h*(2r-h) = (d/2)^2
o, 2rh – h^2 = d^2/4
entonces, r = d^2/8h + h/2 - Entonces, el radio del círculo
C++
// C++ program to find // radius of the circle // when the width and height // of an arc is given #include <bits/stdc++.h> using namespace std; // Function to find the radius void rad(double d, double h) { cout << "The radius of the circle is " << ((d * d) / (8 * h) + h / 2) << endl; } // Driver code int main() { double d = 4, h = 1; rad(d, h); return 0; }
Java
// Java program to find // radius of the circle // when the width and height // of an arc is given class GFG { // Function to find the radius static void rad(double d, double h) { System.out.println( "The radius of the circle is " + ((d * d) / (8 * h) + h / 2)); } // Driver code public static void main(String[] args) { double d = 4, h = 1; rad(d, h); } } /* This code contributed by PrinciRaj1992 */
Python3
# Python3 program to find # radius of the circle # when the width and height # of an arc is given # Function to find the radius def rad(d, h): print("The radius of the circle is", ((d * d) / (8 * h) + h / 2)) # Driver code d = 4; h = 1; rad(d, h); # This code is contributed by 29AjayKumar
C#
// C# program to find // radius of the circle // when the width and height // of an arc is given using System; class GFG { // Function to find the radius static void rad(double d, double h) { Console.WriteLine( "The radius of the circle is " + ((d * d) / (8 * h) + h / 2)); } // Driver code public static void Main() { double d = 4, h = 1; rad(d, h); } } // This code is contributed by AnkitRai01
PHP
<?php // PHP program to find radius of // the circle when the width and // height of an arc is given // Function to find the radius function rad($d, $h) { echo "The radius of the circle is ", (($d * $d) / (8 * $h) + $h / 2), "\n"; } // Driver code $d = 4; $h = 1; rad($d, $h); // This code is contributed by ajit ?>
Javascript
<script> // Javascript program to find // radius of the circle // when the width and height // of an arc is given // Function to find the radius function rad(d, h) { document.write("The radius of the circle is " +((d * d) / (8 * h) + h / 2)); } // Driver code var d = 4, h = 1; rad(d, h); </script>
Producción:
The radius of the circle is 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