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

   2024-10-13 6570
核心提示:以下是一个计算三角形面积的C语言代码示例:#include stdio.hint main() {float base, height, area;// 输入三角形的底边和高pri

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

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

 
举报打赏
 
更多>同类维修大全
推荐图文
推荐维修大全
点击排行

网站首页  |  关于我们  |  联系方式网站留言    |  赣ICP备2021007278号