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

โปรแกรมคำนวณพื้นที่วงกลมล้อมรอบสามเหลี่ยมด้านเท่า


วงกลมล้อมรอบ (circumcircle) คือวงกลมที่ล้อมรูปหลายเหลี่ยมปกติ สามเหลี่ยมที่ล้อมอยู่ภายในคือสามเหลี่ยมด้านเท่า พื้นที่หาได้จากสูตร:

Area = (a × a × (π / 3))

โค้ดใช้สูตร (a×a×(π/3)) ค่า π = 3.14 นิพจน์คำนวณเป็น float

ตัวอย่าง

#include <stdio.h> #include <math.h> int main(){ int a = 5; float area; float pie = 3.14; printf("Program to calculate area of Circumcircle of an Equilateral Triangle\n"); printf("The side of the triangle is %d \n", a); area = ((pie/3)*a*a); printf("The area of of Circumcircle of an Equilateral Triangle is %f \n", area); return 0; }

ผลลัพธ์

Program to calculate area of Circumcircle of an Equilateral Triangle The side of the triangle is 5 The area of circle inscribed inside a square is 19.625000