C程式中內接於等邊三角形的外接圓的內接正方形的面積?
這裡我們將看到一個正方形的面積,它內接於一個圓,而這個圓內接於一個等邊三角形。正方形的邊長為‘a’。圓的半徑為‘r’,等邊三角形的邊長為‘A’。圖示如下。
我們知道內接於等邊三角形的圓的半徑是三角形的內切圓半徑。所以值為 -
所以正方形的對角線為 -
所以正方形的面積為 -
示例
#include <iostream> #include <cmath> using namespace std; float area(float A) { //A is the side of the triangle if (A < 0) //if the value is negative it is invalid return -1; float d = A / sqrt(3); float area = 0.5*d*d; return area; } int main() { float side = 10; cout << "Area is: " << area(side); }
輸出
Area is: 16.6667
廣告