Write a program to find the area of the ellipse.
Example :
Input: minor_axis=10,major_axis=16
Output: 125.6
Approach: Given the length of the major axis and minor axis.
Area is PI*(minor_axis/2)*(major_axis/2),where PI = 3.14
Java
public class AreaofEllipse {public static void main(String[] args) {double minor_axis = 10;double major_axis = 16;double PI = 3.14;double area = areaEllipse(minor_axis, major_axis, PI);System.out.println("Area of Ellipse is " + area);}private static double areaEllipse(double minor_axis,double major_axis, double PI) {return PI * (minor_axis / 2) * (major_axis / 2);}}
C++
#include <bits/stdc++.h>using namespace std;#define PI 3.14//function to find the area of//ellipsedouble areaEllipse(double minor_axis,double major_axis){double area=PI*(minor_axis/2)*(major_axis/2);return area;}int main(){double minor_axis=10;double major_axis=16;double area=areaEllipse(minor_axis,major_axis);cout<<"Area of Ellipse is ";cout<<area<<"\n";return 0;}
No comments:
Post a Comment