# Find the area of ellipse

The problem focuses on calculating the area of an ellipse given the lengths of its major and minor axes. An ellipse is a closed curve that resembles an elongated circle. Calculating the area of an ellipse is an important mathematical computation used in various fields such as physics, engineering, and astronomy.

## Problem Statement

Given the lengths of the major and minor axes of an ellipse, we need to calculate and output the area of the ellipse. The major axis is the longest diameter of the ellipse, and the minor axis is the shortest diameter that is perpendicular to the major axis.

## Example

Consider an ellipse with a major axis of length 4 units and a minor axis of length 3 units. This ellipse can be visualized as follows:

``````
____
/    \
|      |
\____/``````

## Idea to Solve

To solve this problem, we can follow these steps:

1. Calculate the area of the ellipse using the formula: `π * (x_axis * y_axis)`, where `x_axis` is the length of the major axis and `y_axis` is the length of the minor axis.
2. Use the provided values for the major and minor axes to compute the area.

## Pseudocode

``````function ellipse_area(x_axis, y_axis):
area = π * (x_axis * y_axis)
return area

for each test case:
x_axis, y_axis = ellipse axes lengths
result = ellipse_area(x_axis, y_axis)
print("Ellipse [ X-axis :", x_axis, ", Y-axis", y_axis, "]")
print("Area :", result)``````

## Algorithm Explanation

1. For each test case, calculate the area of the ellipse using the provided formula.
2. Print the ellipse's major and minor axis lengths and the calculated area.

## Code Solution

``````//C Program
//Find the area of ellipse
#include <stdio.h>

#include <math.h>
//Calculate area of ellipse by given axis
void ellipse_area(double x_axis, double y_axis)
{
//Calculate Formula
//Major and Minor Axis
//π*(x_axis * y_axis)
double area = (M_PI) * (x_axis * y_axis);
//Display the result of ellipse area
printf(" Ellipse  [ X-axis : %lf, Y-axis %lf] ", x_axis, y_axis);
printf("\n Area : %lf\n\n", area);
}
int main()
{
//Test Cases
ellipse_area(4, 3);
ellipse_area(7, 5);
ellipse_area(7.4, 4.2);
return 0;
}``````

#### Output

`````` Ellipse  [ X-axis : 4.000000, Y-axis 3.000000]
Area : 37.699112

Ellipse  [ X-axis : 7.000000, Y-axis 5.000000]
Area : 109.955743

Ellipse  [ X-axis : 7.400000, Y-axis 4.200000]
Area : 97.640700
``````
``````// Java Program
// Find the area of ellipse
class EllipseArea
{
//Calculate area of ellipse by given axis
public void ellipse_area(double x_axis, double y_axis)
{
//Calculate Formula
//Major and Minor Axis
//π*(x_axis * y_axis)
double area = (Math.PI) * (x_axis * y_axis);
//Display the result of ellipse area
System.out.print(" Ellipse [ X-axis : " + x_axis + ", Y-axis " + y_axis + "] ");
System.out.print("\n Area : " + area + "\n\n");
}
public static void main(String[] args)
{
EllipseArea obj = new EllipseArea();
//Test Cases
obj.ellipse_area(4, 3);
obj.ellipse_area(7, 5);
obj.ellipse_area(7.4, 4.2);
}
}``````

#### Output

`````` Ellipse [ X-axis : 4.0, Y-axis 3.0]
Area : 37.69911184307752

Ellipse [ X-axis : 7.0, Y-axis 5.0]
Area : 109.95574287564276

Ellipse [ X-axis : 7.4, Y-axis 4.2]
Area : 97.64069967357078
``````
``````// C++ Program
// Find the area of ellipse
#include<iostream>
#include<math.h>
using namespace std;
class EllipseArea
{
public:
//Calculate area of ellipse by given axis
void ellipse_area(double x_axis, double y_axis)
{
//Calculate Formula
//Major and Minor Axis
//π*(x_axis *y_axis)
double area = (M_PI) *(x_axis *y_axis);
cout << " Ellipse [ X-axis : " << x_axis << ", Y-axis " << y_axis << "] ";
cout << "\n Area : " << area << "\n\n";
}
};
int main()
{
EllipseArea obj = EllipseArea();
//Test Cases
obj.ellipse_area(4, 3);
obj.ellipse_area(7, 5);
obj.ellipse_area(7.4, 4.2);
return 0;
}``````

#### Output

`````` Ellipse [ X-axis : 4, Y-axis 3]
Area : 37.6991

Ellipse [ X-axis : 7, Y-axis 5]
Area : 109.956

Ellipse [ X-axis : 7.4, Y-axis 4.2]
Area : 97.6407
``````
``````// C# Program
// Find the area of ellipse
using System;
class EllipseArea
{
//Calculate area of ellipse by given axis
public void ellipse_area(double x_axis, double y_axis)
{
//Calculate Formula
//Major and Minor Axis
//π*(x_axis * y_axis)
double area = (Math.PI) * (x_axis * y_axis);
Console.Write(" Ellipse [ X-axis : " + x_axis + ", Y-axis " + y_axis + "] ");
Console.Write("\n Area : " + area + "\n\n");
}
public static void Main(String[] args)
{
EllipseArea obj = new EllipseArea();
//Test Cases
obj.ellipse_area(4, 3);
obj.ellipse_area(7, 5);
obj.ellipse_area(7.4, 4.2);
}
}``````

#### Output

`````` Ellipse [ X-axis : 4, Y-axis 3]
Area : 37.6991118430775

Ellipse [ X-axis : 7, Y-axis 5]
Area : 109.955742875643

Ellipse [ X-axis : 7.4, Y-axis 4.2]
Area : 97.6406996735708
``````
``````<?php
// Php Program
// Find the area of ellipse
class EllipseArea
{
//Calculate area of ellipse by given axis
public 	function ellipse_area(\$x_axis, \$y_axis)
{
//Calculate Formula
//Major and Minor Axis
//π*(x_axis *y_axis)
\$area = (M_PI) *(\$x_axis *\$y_axis);
//Display the result of ellipse area
echo(" Ellipse [ X-axis : ". \$x_axis .", Y-axis ". \$y_axis ."] ");
echo("\n Area : ". \$area ."\n\n");
}
}

function main()
{
\$obj = new EllipseArea();
//Test Cases
\$obj->ellipse_area(4, 3);
\$obj->ellipse_area(7, 5);
\$obj->ellipse_area(7.4, 4.2);
}
main();``````

#### Output

`````` Ellipse [ X-axis : 4, Y-axis 3]
Area : 37.699111843078

Ellipse [ X-axis : 7, Y-axis 5]
Area : 109.95574287564

Ellipse [ X-axis : 7.4, Y-axis 4.2]
Area : 97.640699673571
``````
``````// Node Js Program
// Find the area of ellipse
class EllipseArea
{
//Calculate area of ellipse by given axis
ellipse_area(x_axis, y_axis)
{
//Calculate Formula
//Major and Minor Axis
//π*(x_axis *y_axis)
var area = (Math.PI) *(x_axis *y_axis);
//Display the result of ellipse area
process.stdout.write(" Ellipse [ X-axis : " + x_axis + ", Y-axis " + y_axis + "] ");
process.stdout.write("\n Area : " + area + "\n\n");
}
}

function main(args)
{
var obj = new EllipseArea();
//Test Cases
obj.ellipse_area(4, 3);
obj.ellipse_area(7, 5);
obj.ellipse_area(7.4, 4.2);
}
main();``````

#### Output

`````` Ellipse [ X-axis : 4, Y-axis 3]
Area : 37.69911184307752

Ellipse [ X-axis : 7, Y-axis 5]
Area : 109.95574287564276

Ellipse [ X-axis : 7.4, Y-axis 4.2]
Area : 97.64069967357078
``````
``````#  Python 3 Program
#  Find the area of ellipse
import math
class EllipseArea :
# Calculate area of ellipse by given axis
def ellipse_area(self, x_axis, y_axis) :
# Calculate Formula
# Major and Minor Axis
# π*(x_axis * y_axis)
area = (math.pi) * (x_axis * y_axis)
# Display the result of ellipse area
print(" Ellipse [ X-axis : ", x_axis ,", Y-axis ", y_axis ,"] ")
print(" Area : ", area ,"\n")

def main() :
obj = EllipseArea()
# Test Cases
obj.ellipse_area(4, 3)
obj.ellipse_area(7, 5)
obj.ellipse_area(7.4, 4.2)

if __name__ == "__main__": main()``````

#### Output

`````` Ellipse [ X-axis :  4 , Y-axis  3 ]
Area :  37.69911184307752

Ellipse [ X-axis :  7 , Y-axis  5 ]
Area :  109.95574287564276

Ellipse [ X-axis :  7.4 , Y-axis  4.2 ]
Area :  97.64069967357078
``````
``````#  Ruby Program
#  Find the area of ellipse
class EllipseArea

# Calculate area of ellipse by given axis
def ellipse_area(x_axis, y_axis)

# Calculate Formula
# Major and Minor Axis
# π*(x_axis * y_axis)
area = (Math::PI) * (x_axis * y_axis)
# Display the result of ellipse area
print(" Ellipse [ X-axis  :", x_axis ,", Y-axis ", y_axis ,"] ")
print("\n Area  :", area ,"\n\n")
end
end
def main()

obj = EllipseArea.new()
# Test Cases
obj.ellipse_area(4, 3)
obj.ellipse_area(7, 5)
obj.ellipse_area(7.4, 4.2)
end
main()``````

#### Output

`````` Ellipse [ X-axis  :4, Y-axis 3]
Area  :37.69911184307752

Ellipse [ X-axis  :7, Y-axis 5]
Area  :109.95574287564276

Ellipse [ X-axis  :7.4, Y-axis 4.2]
Area  :97.64069967357078

``````
``````// Scala Program
// Find the area of ellipse
class EllipseArea
{
//Calculate area of ellipse by given axis
def ellipse_area(x_axis: Double, y_axis: Double): Unit = {
//Calculate Formula
//Major and Minor Axis
//π*(x_axis * y_axis)
var area: Double = (Math.PI) * (x_axis * y_axis);
//Display the result of ellipse area
print(" Ellipse [ X-axis : " + x_axis + ", Y-axis " + y_axis + "] ");
print("\n Area : " + area + "\n\n");
}
}
object Main
{
def main(args: Array[String]): Unit = {
var obj: EllipseArea = new EllipseArea();
//Test Cases
obj.ellipse_area(4, 3);
obj.ellipse_area(7, 5);
obj.ellipse_area(7.4, 4.2);
}
}``````

#### Output

`````` Ellipse [ X-axis : 4.0, Y-axis 3.0]
Area : 37.69911184307752

Ellipse [ X-axis : 7.0, Y-axis 5.0]
Area : 109.95574287564276

Ellipse [ X-axis : 7.4, Y-axis 4.2]
Area : 97.64069967357078
``````
``````// Swift Program
// Find the area of ellipse
class EllipseArea
{
//Calculate area of ellipse by given axis
func ellipse_area(_ x_axis: Double, _ y_axis: Double)
{
//Calculate Formula
//Major and Minor Axis
//π*(x_axis * y_axis)
let area: Double = (Double.pi) * (x_axis * y_axis);
//Display the result of ellipse area
print(" Ellipse [ X-axis : ", x_axis ,", Y-axis ", y_axis ,"] ", terminator: "");
print("\n Area : ", area ,"\n\n", terminator: "");
}
}
func main()
{
let obj: EllipseArea = EllipseArea();
//Test Cases
obj.ellipse_area(4, 3);
obj.ellipse_area(7, 5);
obj.ellipse_area(7.4, 4.2);
}
main();``````

#### Output

`````` Ellipse [ X-axis :  4.0 , Y-axis  3.0 ]
Area :  37.6991118430775

Ellipse [ X-axis :  7.0 , Y-axis  5.0 ]
Area :  109.955742875643

Ellipse [ X-axis :  7.4 , Y-axis  4.2 ]
Area :  97.6406996735708
``````

## Output Explanation

The mentioned code runs three test cases and calculates the areas of ellipses with different major and minor axis lengths. The output includes the ellipse's major and minor axis lengths and the corresponding calculated areas.

## Time Complexity

The time complexity of this code is O(1) for each test case. The calculations involve basic arithmetic operations and the constant value π (pi), which take constant time. Therefore, the overall time complexity remains constant for each test case.

## Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.