Q:

Write a Program to find the Perimeter of Ellipse

belongs to collection: Miscellaneous Programs Examples

0

Before writing the program of calculating the perimeter of an ellipse in different programming languages, firstly we have to know about what is ellipse and its perimeter's formula.

What is Ellipse?

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.

Perimeter of Ellipse

Perimeter of Ellipse = 2 * π * sqrt( (a2 + b2) / 2 )
Where, a is the semi-major axis of an ellipse, b is the semi-minor axis of the same ellipse, and the value of π is 3.14.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program of calculating the perimeter of an ellipse in different Programming languages

Program 1: Write a Program in C language:

// This is a C program which uses a function to find the perimeter of ellipse.  
#include <stdio.h>  
float find_Perimeter_of_ellipse(float a, float b) // It is a C function to find perimeter   
{   
float Perimeter_of_ellipse;  
Perimeter_of_ellipse= 2 * 3.14 * sqrt( ( (a* a) + (b * b) ) / 2 ); // It is a formula for calculating a perimeter of ellipse   
return (Perimeter_of_ellipse);   
}   
float main()   
{   
float a;   
float b;  
printf("Enter the semi-major axis of the ellipse:");   
scanf("%f",&a);  
printf("Enter the semi-minor axis of the ellipse:");   
scanf("%f",&b);  
printf("Perimeter of the ellipse is: %f", find_Perimeter_of_ellipse(a, b));     
return 0;   
}   

 

Output of Above C program:

Enter the semi-major axis of the ellipse:5
Enter the semi-minor axis of the ellipse:10
Perimeter of the ellipse is: 49.647758

 

Program 2: Write a Program in Java language:

// This is a program written in Java Languages, which finds the perimeter of the ellipse.  
import java.lang.Math;  
class findperimeter {   
static double find_Perimeter_of_ellipse(float a, float b)   
{    
double Perimeter_of_ellipse;  
Perimeter_of_ellipse = 2 * 3.14 * Math.sqrt( ( (a* a) + (b * b) ) / 2);  
return(Perimeter_of_ellipse);   
}   
// Driver method   
public static void main(String[] args)   
{   
float a= 5, b = 10;   
System.out.println("The Perimeter of a ellipse is:");  
System.out.println(find_Perimeter_of_ellipse(a, b));   
}   
}  

 

Output of Above Java program:

The Perimeter of a ellipse is:
49.647759264643554

 

Program 3: Write a Program in PHP programming language.

<?php   
// This a  PHP program which finds the perimeter of a ellipse.    
// Function to find perimeter   
function find_Perimeter_of_ellipse($a, $b)   
{     
$Perimeter_of_ellipse = 2 * 3.14 * sqrt( ( ($a* $a) + ($b * $b) ) / 2 ); // It is a formula which finds the perimeter  and store the value in the perimeter_of_ellipse variable.   
return ($Perimeter_of_ellipse);   
}   
$a = 5;   
$b = 10;  
  
echo find_Perimeter_of_ellipse($a, $b);   
?>  

 

Output of Above PHP program:

49.647759264644

 

Program 4: Write a Program in Python programming language.

# This is a python program which finds the perimeter of a ellipse.   
# It is a function to find the perimeter of ellipse  
from math import sqrt  
def find_Perimeter_of_ellipse(a, b):  
    return ( 2 * 3.14 * sqrt( ( (a* a) + (b * b) ) / 2 )) # It is a formula which finds the value of perimeter.   
a = 5  
b= 10  
print(find_Perimeter_of_ellipse(a, b) )  

 

Output of Above Python program:

49.647759264644

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Miscellaneous Programs Examples

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a program to calculate the Altitude of Isosc... >>
<< Write a Program to calculate the Surface Area of H...