Radius of a circle having area equal to the sum of area of the circles having given radii - GeeksforGeeks

04 May, 2021
Given two integers r1 and r2, representing the radius of two circles, the task is to find the radius of the circle having area equal to the sum of the area of the two circles having given radii.
Examples:
Input:r1 = 8r2 = 6Output:10Explanation:Area of circle with radius 8 = 201.061929 Area of a circle with radius 6 = 113.097335Area of a circle with radius 10 = 314.159265
Input:r1 = 2r2 = 2Output:2.82843
Approach: Follow the steps below to solve the problem:
Calculate area of the first circle is a1 = 3.14 * r1 * r1.Calculate area of the second circle is a2 = 3.14 * r2 * r2.Therefore, area of the third circle is a1 + a2.Radius of the third circle is sqrt(a3 / 3.14)
Calculate area of the first circle is a1 = 3.14 * r1 * r1.
Calculate area of the second circle is a2 = 3.14 * r2 * r2.
Therefore, area of the third circle is a1 + a2.
Radius of the third circle is sqrt(a3 / 3.14)
Below is the implementation of the following approach.
C++14
Java
Python3
C#
Javascript
// C++ implementation of// the above approach #include <bits/stdc++.h>using namespace std; // Function to calculate radius of the circle// having area equal to sum of the area of// two circles with given radiidouble findRadius(double r1, double r2){    double a1, a2, a3, r3;     // Area of first circle    a1 = 3.14 * r1 * r1;     // Area of second circle    a2 = 3.14 * r2 * r2;     // Area of third circle    a3 = a1 + a2;     // Radius of third circle    r3 = sqrt(a3 / 3.14);     return r3;} // Driver Codeint main(){    // Given radius    double r1 = 8, r2 = 6;     // Prints the radius of    // the required circle    cout << findRadius(r1, r2);     return 0;}
// Java program to implement// the above approachimport java.util.*; class GFG{   // Function to calculate radius of the circle// having area equal to sum of the area of// two circles with given radiistatic double findRadius(double r1, double r2){    double a1, a2, a3, r3;     // Area of first circle    a1 = 3.14 * r1 * r1;     // Area of second circle    a2 = 3.14 * r2 * r2;     // Area of third circle    a3 = a1 + a2;     // Radius of third circle    r3 = Math.sqrt(a3 / 3.14);    return r3;}    // Driver codepublic static void main(String[] args){       // Given radius    double r1 = 8, r2 = 6;     // Prints the radius of    // the required circle    System.out.println((int)findRadius(r1, r2));}} // This code is contributed by code_hunt.
# Python program to implement# the above approach # Function to calculate radius of the circle# having area equal to sum of the area of# two circles with given radiidef findRadius(r1, r2):    a1, a2, a3, r3 = 0, 0, 0, 0;     # Area of first circle    a1 = 3.14 * r1 * r1;     # Area of second circle    a2 = 3.14 * r2 * r2;     # Area of third circle    a3 = a1 + a2;     # Radius of third circle    r3 = ((a3 / 3.14)**(1/2));    return r3; # Driver codeif __name__ == '__main__':     # Given radius    r1 = 8; r2 = 6;     # Prints the radius of    # the required circle    print(int(findRadius(r1, r2))); # This code is contributed by 29AjayKumar
// C# program to implement// the above approachusing System; class GFG{ // Function to calculate radius of the circle// having area equal to sum of the area of// two circles with given radiistatic double findRadius(double r1, double r2){    double a1, a2, a3, r3;     // Area of first circle    a1 = 3.14 * r1 * r1;     // Area of second circle    a2 = 3.14 * r2 * r2;     // Area of third circle    a3 = a1 + a2;     // Radius of third circle    r3 = Math.Sqrt(a3 / 3.14);    return r3;}   // Driver code  static void Main()  {         // Given radius    double r1 = 8, r2 = 6;     // Prints the radius of    // the required circle    Console.WriteLine((int)findRadius(r1, r2));  }} // This code is contributed by susmitakundugoaldanga
<script> // Javascript program of the above approach  // Function to calculate radius of the circle// having area equal to sum of the area of// two circles with given radiifunction findRadius(r1, r2){    let a1, a2, a3, r3;      // Area of first circle    a1 = 3.14 * r1 * r1;      // Area of second circle    a2 = 3.14 * r2 * r2;      // Area of third circle    a3 = a1 + a2;      // Radius of third circle    r3 = Math.sqrt(a3 / 3.14);    return r3;}        // Driver Code         // Given radius    let r1 = 8, r2 = 6;      // Prints the radius of    // the required circle    document.write(findRadius(r1, r2));  </script>
  
10
 
Time Complexity: O(1)Space Complexity: O(1) 
code_hunt
susmitakundugoaldanga
29AjayKumar
avijitmondal1998
Circles
Geometric
Mathematical
Mathematical
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Program for distance between two points on earth
Convex Hull | Set 1 (Jarvis's Algorithm or Wrapping)
Line Clipping | Set 1 (Cohen–Sutherland Algorithm)
Convex Hull | Set 2 (Graham Scan)
Optimum location of point to minimize total distance
Program for Fibonacci numbers
Write a program to print all permutations of a given string
Set in C++ Standard Template Library (STL)
C++ Data Types
Coin Change | DP-7