การคำนวณหาพื้นที่วงกลม ภาษา C
สูตรวงกลม
พื้นที่วงกลม = พาย x รัศมี2
จะได้ A = π r2
...............................
#include <stdio.h> #include <math.h> int main() { float r; printf(" Input Radius : "); scanf("%f", &r); printf("\n The area of a circle is %.2f \n\n", M_PI * (r * r) ); return 0; }
อธิบาย M_PI เป็นฟังก์ชันของการ include math.h มา มีค่าเท่ากับ 3.14159265358979323846
r = ค่ารัศมีของวงกลม
ผลการรัน
Input Radius : 5.9 The area of a circle is 109.36