c语言三角形面积代码怎么写
导读:以下是一个计算三角形面积的C语言代码示例: #include <stdio.h> int main( { float base, height, area; // 输入三角形的底边和高 printf...
以下是一个计算三角形面积的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;
}
运行该程序后,用户可以输入三角形的底边和高,程序将计算并输出三角形的面积。
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: c语言三角形面积代码怎么写
本文地址: https://pptw.com/jishu/679577.html