โค้ดภาษาซี การหาพื้นที่สามเหลี่ยม ภาษา C
สูตรการหาพื้นที่สามเหลี่ยม
พื้นที่สามเหลี่ยม = 1/2 x ฐาน x สูง
- #include <stdio.h>
intmain()- {
floatbase;floatheight;floatresult;printf("\Input value of base : ");scanf("%f", &base);printf("Input value of height : ");scanf("%f", &height);- result = 0.5 * base * height ;
printf("\Area of a Triangle is %.2f \n\n",result);return0;- }
คำอธิบาย
base คือ ตัวแปรที่ใช้เก็บค่า ฐาน ที่เรากรอกเข้าไป
height คือ ตัวแปรที่ใช้เก็บค่าความ สูง ที่เรากรอกเข้าไป0.5 * base * height คือ คำนวณหาพื้นที่สามเหลี่ยมตามสูตร (1/2 x ฐาน x สูง)
result คือ ผลลัพธ์ที่ได้จากการคำนวณ