Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to find area of a Circular Segment in C++
In this tutorial, we will be discussing a program to find area of a circular segment.
Making a chord in a given sphere divides it into two segments - major and minor. Given the radius of the circle and angle making the minor segment, we are required to find the areas of both segments.
Example
#include <bits/stdc++.h>
using namespace std;
float pi = 3.14159;
//finding area of segment
float area_of_segment(float radius, float angle){
float area_of_sector = pi * (radius * radius)*(angle / 360);
float area_of_triangle = (float)1 / 2 *(radius * radius) *
sin((angle * pi) / 180);
return area_of_sector - area_of_triangle;
}
int main() {
float radius = 10.0, angle = 90.0;
cout << "Area of minor segment = "
<< area_of_segment(radius, angle) << endl;
cout << "Area of major segment = "
<< area_of_segment(radius, (360 - angle));
return 0;
}
Output
Area of minor segment = 28.5397 Area of major segment = 285.619
Advertisements