用 C++ 编写程序求圆弧面积
在本教程中,我们将讨论一个求圆弧面积的程序。
在一个给定的球体中画一条弦会将其分成两个部分——大段和小段。已知圆的半径和构成小段的角,要求找出这两个部分的面积。
示例
#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; }
输出
Area of minor segment = 28.5397 Area of major segment = 285.619
广告