温馨提示×

c语言三角形面积代码怎么写

小亿
241
2024-05-29 19:41:11
栏目: 编程语言
C语言开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

以下是一个计算三角形面积的C语言代码示例:

#include <stdio.h>

int main() {
    float base, height, area;

    // 输入三角形的底边和高
    printf("Enter the base of the triangle: ");
    scanf("%f", &base);
    printf("Enter the height of the triangle: ");
    scanf("%f", &height);

    // 计算三角形的面积
    area = 0.5 * base * height;

    // 输出结果
    printf("The area of the triangle is: %.2f\n", area);

    return 0;
}

运行该程序后,用户可以输入三角形的底边和高,程序将计算并输出三角形的面积。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:python三角形面积代码怎么写

0