What is Concentric Circle?
Concentric circle คือวงกลมในวงกลม แปลว่ามีศูนย์กลางร่วมกัน แต่มีรัศมีต่างกัน คือ r1 และ r2 โดย r2 > r1 พื้นที่ระหว่างสองวงกลม concentric เรียกว่า annulus
ภาพ Concentric Circle

ปัญหา
ให้สองวงกลม concentric รัศมี r1 และ r2 โดย r2 > r1 หาพื้นที่ระหว่างทั้งสองวงกลม (ส่วนที่ไฮไลท์สีน้ำเงิน)
คำนวณพื้นที่ระหว่างสองวงกลมได้จากการลบพื้นที่วงกลมเล็กออกจากวงกลมใหญ่
วงกลมใหญ่รัศมี r2 วงกลมเล็กรัศมี r1

ตัวอย่าง
Input-: r1=3 r2=4 Output-: area between two given concentric circle is :21.98
อัลกอริทึม
Start Step 1 -> define macro as #define pi 3.14 Step 2 -> Declare function to find area between the two given concentric circles double calculateArea(int x, int y) set double outer = pi * x * x Set double inner = pi * y * y return outer-inner step 3 -> In main() Declare variable as int x = 4 and int y = 3 Print calculateArea(x,y) Stop
ตัวอย่าง
#include <bits/stdc++.h> #define pi 3.14 using namespace std; // Function to find area between the two given concentric circles double calculateArea(int x, int y){ double outer = pi * x * x; double inner = pi * y * y; return outer-inner; } int main(){ int x = 4; int y = 3; cout <<"area between two given concentric circle is : "<<calculateArea(x, y); return 0; }ผลลัพธ์
area between two given concentric circle is :21.98