当前位置:网站首页>输入三角形边长,求面积
输入三角形边长,求面积
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: the interpretability of the transformer model of functional genomics
- [distinguish the meaning and usage of constant pointer and pointer constants const int * and int * const]
- Tencent cloud client command line tool tccli main process analysis
- Use steps of Charles' packet capturing
- Using pycaret for data mining: association rule mining
- [AUTOSAR candrive 1. learn the function and structure of candrive]
- 硬件知识2--协议类(基于百问网硬件操作大全视频教程)
- Read and write file data
- 《高分子合成工艺》简答题答案
- Lvgl8.1 version notes
猜你喜欢

NVIDIA NVIDIA released H100 GPU, and the water-cooled server is adapted on the road

Interpretation of the paper: iterative feature representation method to improve the prediction performance of N7 methylguanosine (m7G) sites

钢结构基本原理试题及答案

Green data center: comprehensive analysis of air-cooled GPU server and water-cooled GPU server

【AUTOSAR COM 1.通信协议栈介绍】

Baidu Shen Shuo: focus on the scene, deeply cultivate the industry, and bring practical results to enterprise Digitalization

Interpretation of the paper: develop a prediction model based on multi-layer deep learning to identify DNA N4 methylcytosine modification

Examen des principes fondamentaux de la structure en acier

ARM架构与编程3--按键控制LED(基于百问网ARM架构与编程教程视频)

Data analysis (II)
随机推荐
高电压技术基础知识
【AUTOSAR DCM 1.模块简介(DSL,DSD,DSP)】
Deep learning neural network
Using Google or tools to solve logical problems: Zebra problem
[AUTOSAR candrive 1. learn the function and structure of candrive]
利用or-tools来求解路径规划问题(TSP)
高等代数知识结构
博客搭建四:将自己的博客加入百度和谷歌收录的方法
Using or tools to solve path planning problem (VRP)
ARM架构与编程3--按键控制LED(基于百问网ARM架构与编程教程视频)
线性规划之Google OR-Tools 简介与实战
钢结构基本原理全面详细总结
钢结构基本原理题库
Interpretation of the paper: using attention mechanism to improve the identification of N6 methyladenine sites in DNA
G2o installation path record -- for uninstallation
Green data center: comprehensive analysis of air-cooled GPU server and water-cooled GPU server
Opencv library installation path (don't open this)
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"?
高电压技术试题及答案
深度卷积生成对抗网络