Write a program to find the area of the sector.
Example
Input: angle=60,radius=5
Output: 13.083
Approach 1: Given angle(in degree) and radius.
Area is PI*(angle/360)*radius*radius,where PI = 3.14
Java
public class AreaofSector {public static void main(String[] args) {double angle = 60;double radius = 5;double PI = 3.14;double area = areaSector(angle, radius, PI);System.out.println("Area of Sector is " + area);}private static double areaSector(double angle, double radius, double PI) {return PI * (angle / 360) * radius * radius;}}
C++
#include <bits/stdc++.h>using namespace std;#define PI 3.14//function to find the area//of sectordouble areaSector(double angle,double radius){double area=PI*(angle/360)*radius*radius;return area;}int main(){//angle value in degreedouble angle=60;double radius=5;double area=areaSector(angle,radius);cout<<"Area of sector is ";cout<<area<<"\n";return 0;}
Approach 2: Given angle in radian and radius.
Area is PI*angle*radius*radius.
C++
#include <bits/stdc++.h>using namespace std;#define PI 3.14//function to find the area//of sectordouble areaSector(double angle,double radius){double area=PI*(angle)*radius*radius;return area;}int main(){//angle value in radiandouble angle=0.166;double radius=5;double area=areaSector(angle,radius);cout<<"Area of sector is ";cout<<area<<"\n";return 0;}
No comments:
Post a Comment