当前位置:网站首页>输入三角形边长,求面积
输入三角形边长,求面积
2022-07-23 05:44:00 【xiq1212】
输入三角形边长,求面积
公式:s = 1/2(a+b+c);area = √s*(s-a)(s-b)(s-c)
这条代码看似简单,但是对应的公式中存在着好几个“小坑”。
1.第一个需要注意的就是
‘/’整除——取整,假如你的实际运算结果是一个比1小的整数,计算机就会自动给你取0。这里可以强制运算结果转化为,单精度或者双精度浮点型数据。
s = 1/2(a+b+c);area = √s*(s-a)*(s-b)*(s-c);
2.第二个就是这里引用了sqrt求根函数
所以我们需要再一开始就链接math库。
#include<math.h>
3.完整版代码
#include <stdio.h>
#include <math.h>
int main(int argc, const char *argv[])
{
int s,a,b,c;
printf("请输入三角形边长:\n");
scanf("%d%d%d",&a,&b,&c);
if(a+b<c||a+c<b||b+c<a)
{
printf("err\n");
return -1;
}
else if(a<0||b<0||c<0)
{
printf("err\n");
return -1;
}
else
{
s=(double)1/2*(a+b+c);
s=sqrt(s*(s-a)*(s-b)*(s-c));
printf("三角形的面积为:%d\n",s);
}
return 0;
}
4.运行结果:

边栏推荐
- 时间序列的数据分析(二):数据趋势的计算
- 高电压技术试题及答案
- Interpretation of the paper: develop and verify the deep learning system to classify the etiology of macular hole and predict the anatomical results
- 高电压技术学习总结
- Comment se développe le serveur GPU refroidi à l'eau dans le Centre de données dans le cadre de l'informatique est - Ouest?
- Interpretation of the paper: attention based multi label neural network for comprehensive prediction and interpretation of 12 widely existing RNA modifications
- Introduction and practice of Google or tools for linear programming
- Read and write file data
- NLP natural language processing - Introduction to machine learning and natural language processing (I)
- Deep learning neural network
猜你喜欢

Six trends and eight technologies of high-performance computing in data centers under "data center white paper 2022" and "computing from the east to the west"

【AUTOSAR COM 2.通信协议栈进阶介绍】

深度卷积生成对抗网络

A hundred schools of thought contend at the 2021 trusted privacy computing Summit Forum and data security industry summit

Data mining scenario - false invoice

单片机学习笔记8--按键和外部中断(基于百问网STM32F103系列教程)

CPC client installation tutorial

Examen des principes fondamentaux de la structure en acier

高等代数知识结构
![[AUTOSAR com 3. signal sending and receiving process tx/rx]](/img/f7/e5f89a51cf990ede61ce342e88e5d6.png)
[AUTOSAR com 3. signal sending and receiving process tx/rx]
随机推荐
高电压技术重点知识整理
Baidu Shen Shuo: focus on the scene, deeply cultivate the industry, and bring practical results to enterprise Digitalization
Use steps of Charles' packet capturing
【AUTOSAR COM 4.Com服务层模块的介绍】
The online seminar on how to help data scientists improve data insight was held on June 8
Data analysis of time series (I): main components
【Autosar 存储Stack NVM】
How to develop the computing power and AI intelligent chips in the data center of "digital computing in the East and digital computing in the west"?
高分子物理名词解释
Gartner research: how is China's digital development compared with the world level? Can high-performance computing dominate?
Eigen multi version library installation
How to build a liquid cooling data center is supported by blue ocean brain liquid cooling technology
单片机学习笔记9--串口通信(基于百问网STM32F103系列教程)
利用google or-tools 求解逻辑难题:斑马问题
How to develop the liquid cooled GPU server in the data center under the "east to West calculation"?
Smart pointer shared_ PTR and unique_ ptr
数据分析(一)
Using or tools to solve the path planning problem (TSP)
G2o installation path record -- for uninstallation
数据挖掘场景-发票虚开