以 C++ 編寫可在任何正多邊形中找出外接圓程式
本題給出了兩個數字,表示多邊形的邊數 N 和每條邊的長度 A。我們的任務是編寫一個程式,在 C++ 中找出任何正多邊形的外接圓。
題目描述 − 在此,我們需要找出邊數和長度已知正多邊形外接圓的半徑和麵積。
我們舉個例子來理解這個問題,
輸入
n = 4 a = 2
程式演示了我們解決方案的工作原理,
示例
#include <bits/stdc++.h>
using namespace std;
void CalcRadAreaCircumcircle(float n, float a) {
float r = a / sqrt( 2 * ( 1 - cos(360 / n)));
cout<<"The radius of Circumcircle is "<<r<<endl;
cout<<"The area of circumcircle is "<<((3.14)*r*r);
}
int main() {
float n = 5, a = 6;
CalcRadAreaCircumcircle(n, a);
return 0;
}輸出
The radius of Circumcircle is 3.02487 The area of circumcircle is 28.7305
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP