พื้นที่เป็นปริมาณที่แสดงขอบเขตของรูปใน 2 มิติ พื้นที่วงกลมคือพื้นที่ที่วงกลมครอบคลุมในระนาบ 2 มิติ
ต้องการรัศมี (r) หรือเส้นผ่านศูนย์กลาง (d = 2×r)
สูตรคำนวณพื้นที่ = (π×r²) หรือ {(π×d²)/4}
โค้ดตัวอย่าง
หาพื้นที่วงกลมด้วยรัศมี
#include <stdio.h> int main(void) { float pie = 3.14; int radius = 6; printf("The radius of the circle is %d \n", radius); float area = (float)(pie*radius*radius); printf("The area of the given circle is %f", area); return 0; }ผลลัพธ์
The radius of the circle is 6 The area of the given circle is 113.040001
โค้ดตัวอย่าง
ใช้รัศมีและ math.h ใช้ pow() หากำลังสอง
#include <stdio.h> int main(void) { float pie = 3.14; int radius = 6; printf("The radius of the circle is %d \n", radius); float area = (float)(pie*pow(radius,2)); printf("The area of the given circle is %f", area); return 0; }ผลลัพธ์
The radius of the circle is 6 The area of the given circle is 113.040001
โค้ดตัวอย่าง
ใช้เส้นผ่านศูนย์กลาง
#include <stdio.h> int main(void) { float pie = 3.14; int Diameter = 12; printf("The Diameter of the circle is %d \n", Diameter); float area = (float)((pie*Diameter*Diameter)/4); printf("The area of the given circle is %f", area); return 0; }ผลลัพธ์
The Diameter of the circle is 12 The area of the given circle is 113.040001