博客
关于我
C语言-求三角形面积
阅读量:360 次
发布时间:2019-03-04

本文共 613 字,大约阅读时间需要 2 分钟。

三角形面积计算(海伦公式)

# 代码实现
#include 
#include
void main(){ double a, b, c; double p; double s; scanf("%lf%lf%lf", &a, &b, &c); if ((a + b > c) && (a + c > b) && (b + c > a)) { p = (a + b + c) / 2; s = sqrt(p * (p - a) * (p - b) * (p - c)); printf("%lf", s); } else { printf("无法构成三角形"); } }

计算结果

通过上述代码可以计算任意三角形的面积。系统会自动验证输入的三角形边长是否满足三角形不等式,如果满足则使用海伦公式计算面积;如果不满足则提示无法构成三角形。

此外,代码中使用了以下技术细节:

  • 数据类型:使用了double类型来保证计算的精度。
  • 输入输出:采用scanf函数进行用户输入处理。
  • 条件判断:通过三角形不等式(任意两边之和大于第三边)来判断输入的边长是否有效。

系统运行结果显示:输入的三边长度需满足三角形不等式,否则无法计算面积。

转载地址:http://xbch.baihongyu.com/

你可能感兴趣的文章
notepad如何自动对齐_notepad++怎么自动排版
查看>>
Notes on Paul Irish's "Things I learned from the jQuery source" casts
查看>>
Notification 使用详解(很全
查看>>
NotImplementedError: Cannot copy out of meta tensor; no data! Please use torch.nn.Module.to_empty()
查看>>
NotImplementedError: Could not run torchvision::nms
查看>>
nova基于ubs机制扩展scheduler-filter
查看>>
Now trying to drop the old temporary tablespace, the session hangs.
查看>>
nowcoder—Beauty of Trees
查看>>
np.arange()和np.linspace()绘制logistic回归图像时得到不同的结果?
查看>>
np.power的使用
查看>>
NPM 2FA双重认证的设置方法
查看>>
npm build报错Cannot find module ‘webpack/lib/rules/BasicEffectRulePlugin‘解决方法
查看>>
npm build报错Cannot find module ‘webpack‘解决方法
查看>>
npm ERR! ERESOLVE could not resolve报错
查看>>
npm ERR! fatal: unable to connect to github.com:
查看>>
npm ERR! Unexpected end of JSON input while parsing near '...on":"0.10.3","direc to'
查看>>
npm ERR! Unexpected end of JSON input while parsing near ‘...“:“^1.2.0“,“vue-html-‘ npm ERR! A comp
查看>>
npm error Missing script: “server“npm errornpm error Did you mean this?npm error npm run serve
查看>>
npm error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。要解决此问题,1) 安装
查看>>
npm install CERT_HAS_EXPIRED解决方法
查看>>