c语言 float area,c语言计算三角形面积代码(2页)-原创力文档

这篇博客介绍了如何使用C语言计算三角形面积。通过海伦公式和直角三角形的特性,分别编写了两个函数area1和area2。在main函数中,程序会根据用户输入的三角形三边长度,判断是否能构成三角形,如果是直角三角形则使用简便方法计算,否则使用海伦公式。最后,程序将打印出计算得到的三角形面积。
摘要由CSDN通过智能技术生成

1// 计算三角形面积.cpp : 定义控制台应用程序的入口点。

#include "stdafx.h"

#include "math.h"

float area1(float a,float b,float c)//用海伦公式计算三角形面积

{

float s1;

float p;

p = (a+b+c)/2;

s1 = sqrt(p*(p-a)*(p-b)*(p-c));

return s1;

}

float area2(float x,float y)//用简便方法计算三角形面积

{

float s2;

s2 = x*y/2;

return s2;

}

void main()

{

float a;

float b;

float c;

float s1;

float s2;

float x;

float y;

printf("pleace input the first line length: ");//分别输入三边的长度版权文档,请勿用做商业用途

scanf("%f",&a);

printf("pleace input the second line length: ");

scanf("%f",&b);

printf("pleace input the third line length: ");

scanf(&#

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值