ภาพรวมปัญหา
ในปัญหานี้ เราได้รับค่ารัศมี (R) ของครึ่งวงกลม งานของเราคือสร้าง โปรแกรมหาพื้นที่และเส้นรอบรูปของครึ่งวงกลมใน C++
ข้อมูลพื้นฐาน
ครึ่งวงกลม (SemiCircle) คือ รูปปิดที่เป็นครึ่งหนึ่งของวงกลม

ตัวอย่าง
Input
R = 5
Output
area = 39.25 perimeter = 15.7
แนวทางแก้ปัญหา
ใช้สูตรคณิตศาสตร์สำหรับพื้นที่และเส้นรอบรูปของครึ่งวงกลม (มาจากสูตรวงกลมหาร 2):
- พื้นที่ครึ่งวงกลม = ½ × π × r² ≈ 1.571 × r²
- เส้นรอบรูปครึ่งวงกลม = π × r ≈ 3.142 × r (เฉพาะส่วนโค้ง ไม่รวมเส้นผ่านศูนย์กลาง)
ตัวอย่างโปรแกรม
#include <iostream>
using namespace std;
float calaAreaSemi(float R) {
return (1.571 * R * R);
}
float calaPeriSemi(float R) {
return (3.142 * R);
}
int main() {
float R = 5;
cout << "The radius of semicircle is " << R << endl;
cout << "The area of semicircle is " << calaAreaSemi(R) << endl;
cout << "The perimeter of semicircle is " << calaPeriSemi(R) << endl;
return 0;
}
Output
The radius of semicircle is 5 The area of semicircle is 39.275 The perimeter of semicircle is 15.71