Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม C

พื้นที่วงกลมในสี่เหลี่ยมผืนผ้าในครึ่งวงกลม ในภาษา C

ครึ่งวงกลมรัศมี R → สี่เหลี่ยมผืนผ้าสูงสุดที่ใส่ได้: ความยาว = R√2, ความกว้าง = R/√2

วงกลมในสี่เหลี่ยม: รัศมี = ความกว้าง/2 = R/(2√2)

พื้นที่ = π × (R/(2√2))² = πR²/8

โค้ดตัวอย่าง

#include <iostream>
#include <cmath>
using namespace std;

float innerCircleArea(float R) {
    return M_PI * pow(R / (2*sqrt(2)), 2);
}

int main() {
    float R = 12;
    cout << "Area: " << innerCircleArea(R);
    return 0;
}

ผลลัพธ์

Area: 56.547