Open In App

Program to find the Area of an Ellipse

Given an ellipse with a semi-major axis of length a and semi-minor axis of length b. The task is to find the area of an ellipse.
In mathematics, an ellipse is a curve in a plane surrounding by two focal points such that the sum of the distances to the two focal points is constant for every point on the curve or we can say that it is a generalization of the circle.
 



Important points related to Ellipse
 

Area of an ellipse: The formula to find the area of an ellipse is given below: 
 



Area = 3.142 * a * b

where a and b are the semi-major axis and semi-minor axis respectively and 3.142 is the value of π.
Examples: 
 

Input : a = 5, b = 4
Output : 62.48

Input : a = 10, b = 5
Output : 157.1

 




// C++ program to find area of
// an Ellipse.
#include<bits/stdc++.h>
using namespace std;
 
// Function to find area of an
// ellipse.
void findArea( float a, float b)
{
    float Area;
     
    // formula to find the area
    // of an Ellipse.
    Area = 3.142 * a * b ;
     
    // Display the result
    cout << "Area: " << Area;
}
 
// Driver code
int main()
{
    float a = 5, b = 4;
     
    findArea(a, b);
     
    return 0;
}




// Java program to find area of
// an Ellipse.
class GFG {
 
    // Function to find area of an
    // ellipse.
    static void findArea( float a, float b)
    {
        float Area;
         
        // formula to find the area
        // of an Ellipse.
        Area = (float)3.142 * a * b ;
         
        // Display the result
        System.out.println("Area: " + Area);
    }
     
    // Driver code
    public static void main (String[] args)
    {
        float a = 5, b = 4;
         
        findArea(a, b);
    }
}




# Python3 program to find
# area of an Ellipse.
 
# Function to find area
# of an ellipse.
def findArea(a, b):
     
    # formula to find the
    # area of an Ellipse.
    Area = 3.142 * a * b ;
     
    # Display the result
    print("Area:", round(Area, 2));
 
# Driver code
a = 5;
b = 4;
 
findArea(a, b);
 
# This code is contributed
# by mits




// C# program to find area of
// an Ellipse.
using System;
class GFG
{
 
    // Function to find area
    // of an ellipse.
    static void findArea(float a,
                         float b)
    {
        float Area;
         
        // formula to find the
        // area of an Ellipse.
        Area = (float)3.142 * a * b ;
         
        // Display the result
        Console.WriteLine("Area: " +
                           Area);
    }
     
    // Driver code
    public static void Main ()
    {
        float a = 5, b = 4;
         
        findArea(a, b);
    }
}
 
// This code is contributed
// by anuj_67.




<?php
// PHP program to find
// area of an Ellipse.
 
// Function to find area
// of an ellipse.
function findArea($a, $b)
{
    $Area;
     
    // formula to find the
    // area of an Ellipse.
    $Area = 3.142 * $a * $b ;
     
    // Display the result
    echo "Area: " . $Area;
}
 
// Driver code
$a = 5; $b = 4;
 
findArea($a, $b);
 
// This code is contributed
// by anuj_67.
?>




<script>
 
// JavaScript program to find area of
// an Ellipse.   
 
// Function to find area of an ellipse.
    function findArea(a , b) {
        var Area;
 
        // formula to find the area
        // of an Ellipse.
        Area =  3.142 * a * b;
 
        // Display the result
        document.write("Area: " + Area.toFixed(2));
    }
 
    // Driver code
     
        var a = 5, b = 4;
 
        findArea(a, b);
 
// This code is contributed by aashish1995
 
</script>

Output: 
Area: 62.84

 

Time Complexity: O(1)
Auxiliary Space: O(1)


Article Tags :