Given an integer C which is the length of the hypotenuse of a right angled triangle of a circumcircle passing through the centre of the circumcircle. The task is to find the area of the circumcircle.

Examples:
Input: C = 8
Output: 50.26
Input: C = 10
Output: 78.53
Approach: Since the hypotenuse C passes through the center of the circle, the radius of the circle will be C / 2.
And we know that the area of a circle is PI * r2 where PI = 22 / 7 and r is the radius of the circle.
Hence the area of the circumcircle will be PI * (C / 2)2 i.e. PI * C2 / 4.
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
#define PI 3.14159265
using namespace std;
float area_circumscribed( float c)
{
return (c * c * (PI / 4));
}
int main()
{
float c = 8;
cout << area_circumscribed(c);
return 0;
}
|
C
#include <stdio.h>
#define PI 3.14159265
float area_circumscribed( float c)
{
return (c * c * (PI / 4));
}
int main()
{
float c = 8;
printf ( "%f" ,
area_circumscribed(c));
return 0;
}
|
Java
import java.lang.*;
class GFG {
static double PI = 3.14159265 ;
public static double area_cicumscribed( double c)
{
return (c * c * (PI / 4 ));
}
public static void main(String[] args)
{
double c = 8.0 ;
System.out.println(area_cicumscribed(c));
}
}
|
Python3
PI = 3.14159265
def area_cicumscribed(c):
return (c * c * (PI / 4 ))
c = 8.0
print (area_cicumscribed(c))
|
C#
using System;
class GFG {
static double PI = 3.14159265;
public static double area_cicumscribed( double c)
{
return (c * c * (PI / 4));
}
public static void Main()
{
double c = 8.0;
Console.Write(area_cicumscribed(c));
}
}
|
PHP
<?php
$PI = 3.14159265;
function area_circumscribed( $c )
{
global $PI ;
return ( $c * $c * ( $PI / 4));
}
$c = 8;
echo (area_circumscribed( $c ));
?>
|
Javascript
<script>
let PI = 3.14159265;
function area_cicumscribed(c) {
return (c * c * (PI / 4));
}
var c = 8.0;
document.write(area_cicumscribed(c).toFixed(6));
</script>
|
Time complexity: O(1), since there is no loop or recursion.
Auxiliary Space: O(1), since no extra space has been taken.
Another Approach:
To find the area of a circumcircle, we need to know its radius first. In a right-angled triangle, the circumcenter is the midpoint of the hypotenuse. Therefore, the radius of the circumcircle can be calculated as half of the length of the hypotenuse.
Once we have the radius, we can use the formula for the area of a circle, which is:
Area = ? * r^2
where r is the radius.
In this problem, we are given the length of the hypotenuse, which is also the diameter of the circumcircle. Therefore, we can calculate the radius as C/2. Then, we can use the above formula to find the area of the circumcircle.
C++
#include <iostream>
#include <cmath>
using namespace std;
double areaOfCircumcircle( double c) {
double a = c/2.0;
double b = sqrt ( pow (c, 2) - pow (a, 2));
double r = c/2.0;
double area = M_PI* pow (r, 2);
return area;
}
int main() {
double c = 8;
cout << areaOfCircumcircle(c) << endl;
}
|
Java
import java.lang.Math;
public class Main {
public static double areaOfCircumcircle( double c) {
double a = c / 2.0 ;
double b = Math.sqrt(Math.pow(c, 2 ) - Math.pow(a, 2 ));
double r = c / 2.0 ;
double area = Math.PI * Math.pow(r, 2 );
return area;
}
public static void main(String[] args) {
double c = 8 ;
System.out.println(areaOfCircumcircle(c));
}
}
|
Python3
import math
def areaOfCircumcircle(c):
a = c / 2.0
b = math.sqrt( pow (c, 2 ) - pow (a, 2 ))
r = c / 2.0
area = math.pi * pow (r, 2 )
return area
if __name__ = = '__main__' :
c = 8
print (areaOfCircumcircle(c))
|
C#
using System;
public class MainClass {
public static double areaOfCircumcircle( double c) {
double a = c / 2.0;
double b = Math.Sqrt(Math.Pow(c, 2) - Math.Pow(a, 2));
double r = c / 2.0;
double area = Math.PI * Math.Pow(r, 2);
return area;
} public static void Main() {
double c = 8;
Console.WriteLine(areaOfCircumcircle(c));
}
}
|
Javascript
function areaOfCircumcircle(c) {
const a = c/2.0;
const b = Math.sqrt(Math.pow(c, 2) - Math.pow(a, 2));
const r = c/2.0;
const area = Math.PI*Math.pow(r, 2);
return area;
}
const c = 8;
console.log(areaOfCircumcircle(c));
|
Time Complexity: O(1)
Space Complexity: O(1)
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!
Last Updated :
03 Apr, 2023
Like Article
Save Article