Aquí se dan n círculos que se tocan entre sí externamente y están alineados en una fila. Se da la distancia entre los centros del primer y último círculo. Los círculos tienen un radio de igual longitud. La tarea es encontrar el radio de cada círculo.
Ejemplos:
Input: d = 42, n = 4 Output: The radius of each circle is 7 Input: d = 64, n = 5 Output: The radius of each circle is 8
Enfoque :
supongamos que hay n círculos, cada uno de los cuales tiene un radio de longitud r .
Sea, la distancia entre el primer y el último círculo = d
De la figura, está claro,
r + r + (n-2)*2r = d
2r + 2nr – 4r = d
2nr – 2r = d
entonces, r = d /(2n-2)
C++
// C++ program to find radii of the circles // which are lined in a row // and distance between the // centers of first and last circle is given #include <bits/stdc++.h> using namespace std; void radius(int n, int d) { cout << "The radius of each circle is " << d / (2 * n - 2) << endl; } // Driver code int main() { int d = 42, n = 4; radius(n, d); return 0; }
Java
// Java program to find radii of the circles // which are lined in a row // and distance between the // centers of first and last circle is given import java.io.*; class GFG { static void radius(int n, int d) { System.out.print( "The radius of each circle is " +d / (2 * n - 2)); } // Driver code static public void main (String []args) { int d = 42, n = 4; radius(n, d); } } // This code is contributed by anuj_67..
Python3
# Python program to find radii of the circles # which are lined in a row # and distance between the # centers of first and last circle is given def radius(n, d): print("The radius of each circle is ", d / (2 * n - 2)); d = 42; n = 4; radius(n, d); # This code is contributed by PrinciRaj1992
C#
// C# program to find radii of the circles // which are lined in a row // and distance between the // centers of first and last circle is given using System; class GFG { static void radius(int n, int d) { Console.Write( "The radius of each circle is " +d / (2 * n - 2)); } // Driver code static public void Main () { int d = 42, n = 4; radius(n, d); } } // This code is contributed by anuj_67..
Javascript
<script> // javascript program to find radii of the circles // which are lined in a row // and distance between the // centers of first and last circle is given function radius(n , d) { document.write( "The radius of each circle is " +d / (2 * n - 2)); } // Driver code var d = 42, n = 4; radius(n, d); // This code is contributed by 29AjayKumar </script>
Producción:
The radius of each circle is 7
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