梯形的面积和周长的计算程序
梯形是具有至少一对彼此平行的侧面的四边形。梯形的面积和周长可以使用以下公式找到,
周长=各边之和
面积=½x(平行边的长度之和)x平行边之间的垂直距离
代码逻辑-代码将使用5个变量作为梯形的所有边,其中一个用于两个平行边之间的垂直距离。对于面积变量计算,我们将使用一个浮点变量,并将其值初始化。为了计算它,我们将使用公式“½x(平行边的长度之和)x平行边之间的垂直距离”。为了进行周长计算,将为变量分配表达式“(所有边的总和)”。
以下代码显示了计算梯形的面积和周长的程序,
示例
#include <stdio.h>
int main() {
int a = 2 , b = 3 , c = 5 , d = 4, h = 5;
float area, perimeter;
printf("The sides of trapezium are %d , %d , %d , %d \n", a,b,c,d);
printf("Distance between two parallel sides is %d \n", h);
perimeter = a+b+c+d;
area = 0.5 * (a + b) * h ;
printf("Perimeter of the trapezium is %.1f\n", perimeter);
printf("Area of the trapezium is: %.3f", area);
return 0;
}输出结果
The sides of trapezium are 2 , 3 , 5 , 4 Distance between two parallel sides is 5 Perimeter of the trapezium is 14.0 Area of the trapezium is: 12.500
热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志