Find area of the larger circle when radius of the smaller circle and difference in the area is given
Given two integers r and d where r is the radius of the smaller circle and d is the difference of the area of this circle with some larger radius circle. The task is to find the area of the larger circle.
Examples:
Input: r = 4, d = 5
Output: 55.24
Area of the smaller circle = 3.14 * 4 * 4 = 50.24
55.24 – 50.24 = 5
Input: r = 12, d = 3
Output: 455.16
Approach: Let radius of the smaller and the larger circles be r and R respectively and the difference in the areas is given to be d i.e. PI * R2 – PI * r2 = d where PI = 3.14
Or, R2 = (d / PI) + r2.
Now, area of the bigger circle can be calculated as PI * R2.
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14;
double find_area( int r, int d)
{
double R = d / PI;
R += pow (r, 2);
R = sqrt (R);
double area = PI * pow (R, 2);
return area;
}
int main()
{
int r = 4, d = 5;
cout << find_area(r, d);
return 0;
}
|
Java
class GFG
{
static double PI = 3.14 ;
static double find_area( int r, int d)
{
double R = d / PI;
R += Math.pow(r, 2 );
R = Math.sqrt(R);
double area = PI * Math.pow(R, 2 );
return area;
}
public static void main(String[] args)
{
int r = 4 , d = 5 ;
System.out.println(find_area(r, d));
}
}
|
Python3
PI = 3.14
from math import pow , sqrt
def find_area(r, d):
R = d / PI
R + = pow (r, 2 )
R = sqrt(R)
area = PI * pow (R, 2 )
return area
if __name__ = = '__main__' :
r = 4
d = 5
print (find_area(r, d))
|
C#
using System;
public class GFG
{
static double PI = 3.14;
static double find_area( int r, int d)
{
double R = d / PI;
R += Math.Pow(r, 2);
R = Math.Sqrt(R);
double area = PI * Math.Pow(R, 2);
return area;
}
static public void Main ()
{
int r = 4, d = 5;
Console.Write(find_area(r, d));
}
}
|
PHP
<?php
const PI = 3.14;
function find_area( $r , $d )
{
$R = $d / PI;
$R += pow( $r , 2);
$R = sqrt( $R );
$area = PI * pow( $R , 2);
return $area ;
}
$r = 4;
$d = 5;
echo (find_area( $r , $d ));
?>
|
Javascript
<script>
let PI = 3.14;
function find_area(r, d)
{
let R = d / PI;
R += Math.pow(r, 2);
R = Math.sqrt(R);
let area = PI * Math.pow(R, 2);
return area;
}
let r = 4, d = 5;
document.write( find_area(r,d).toFixed(2));
</script>
|
Time complexity: O(logR)
Auxiliary Space: O(1)
Last Updated :
20 Aug, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...