以 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

更新於: 2022 年 5 月 16 日

160 次瀏覽

開啟您的事業

透過完成課程獲得認證

開始吧
廣告
© . All rights reserved.