温馨提示×

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

小亿
82
2024-05-29 19:41:11
栏目: 编程语言

以下是一个计算三角形面积的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;
}

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

0