An ellipse is described as a curve on a plane that surrounds two focal points such that the sum of the distances to the two focal points is constant for every point on the curve. Ellipse has two types of axis – Major Axis and Minor Axis. The longest chord of the ellipse is the major axis. The perpendicular chord to the major axis is the minor axis which bisects the major axis at the center.
Given the lengths of minor and major axis of an ellipse, the task is to find the perimeter of the Ellipse.

Examples:
Input: a = 3, b = 2
Output: 16.0109
Input: a = 9, b = 5
Output: 45.7191
Perimeter of an ellipse is:
Perimeter : 2? * sqrt( (a2 + b2) / 2 )
Where a and b are the semi-major axis and semi-minor axis respectively.
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
void Perimeter( int a, int b)
{
float perimeter;
perimeter = 2 * 3.14 * sqrt ((a * a + b * b) / (2 * 1.0));
cout << perimeter;
}
int main()
{
int a = 3, b = 2;
Perimeter(a, b);
return 0;
}
|
Java
import java.lang.Math;
class GFG1{
static void Perimeter( double a, double b)
{
double Perimeter;
Perimeter = ( double ) 2 * 3.14 * Math.sqrt((a * a + b * b) / ( 2 * 1.0 )) ;
System.out.println( "Perimeter: " + Perimeter);
}
public static void main (String[] args)
{
double a = 3 , b = 2 ;
Perimeter(a , b);
}
}
|
Python3
from math import sqrt
def Perimeter(a, b):
perimeter = 0
perimeter = ( 2 * 3.14 *
sqrt((a * a + b * b) /
( 2 * 1.0 )));
print (perimeter)
a = 3
b = 2
Perimeter(a, b)
|
C#
using System;
class GFG1
{
static void Perimeter( double a, double b)
{
double Perimeter;
Perimeter = ( double )2 * 3.14 *
Math.Sqrt((a * a + b * b) / (2 * 1.0));
Console.WriteLine( "Perimeter: " + Perimeter);
}
public static void Main (String[] args)
{
double a = 3, b = 2;
Perimeter(a , b);
}
}
|
Javascript
<script>
function Perimeter(a , b) {
var Perimeter;
Perimeter = 2 * 3.14 * Math.sqrt((a * a + b * b) / (2 * 1.0));
document.write( "Perimeter: " + Perimeter);
}
var a = 3, b = 2;
Perimeter(a, b);
</script>
|
Time Complexity: O(log n)
Auxiliary Space: O(1)