当前位置:网站首页>详解C语言编程题:任意三条边能否构成三角形,输出该三角形面积并判断其类型
详解C语言编程题:任意三条边能否构成三角形,输出该三角形面积并判断其类型
2022-06-26 13:56:00 【醒醒起来学习啦】
问题:根据输入的三角形的三边判断是否能组成三角形,若可以,则输出它的面积并判断该三角形的类型。
思路:
1、判断三边是否能组成三角形:任意两边之和大于第三边、任意两边之差小于第三边。(这里以前者举例)
2、三角形面积公式(这里用海伦公式):半周长
三角形面积
3、三角形的类型:等边三角形、等腰三角形、直角三角形、一般三角形
代码:
#include <stdio.h>
#include <math.h>
int main()
{
float a, b, c;//定义三角形三边为a、b、c
float p, S;//定义三角形的半周长p、面积S
scanf("%f,%f,%f",&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("三角形的面积为: % f\n", S);
if ((a==b) && (b==c))//三条边相等
printf("等边三角形\n");
else if ((a==b)||(b==c)||(a==c))//任意两边相等
printf("等腰三角形\n");
else if ((a * a + b * b == c * c) || (a * a + c * c == b * b) || (c * c + b * b == a * a))//勾股定理
printf("直角三角形\n");
else printf("一般三角形\n");
}
else printf("不能组成三角形\n");
return 0;
}希望能够帮到你,觉得有用的话就点赞支持一下吧!
边栏推荐
- 印尼投资部长:鸿海考虑在其新首都建立电动公交系统、城市物联网
- How to call self written functions in MATLAB
- IP certificate application process of sectigo
- Comparison of disk partition modes (MBR and GPT)
- Recent important news
- Electron
- Chinese output of PostGIS console is garbled
- Oracle ASMM and AMM
- 2022年最新贵州建筑八大员(机械员)模拟考试题库及答案
- fileinput.js php,fileinput
猜你喜欢

NAACL2022:(代码实践)好的视觉引导促进更好的特征提取,多模态命名实体识别(附源代码下载)...

C language | file operation and error prone points

Sword finger offer 21.57.58 I Double pointer (simple)

Combat readiness mathematical modeling 32 correlation analysis 2

Gartner 2022 Top Strategic Technology Trends Report

Sword finger offer 45.61 Sort (simple)

备战数学建模30-回归分析2

Chinese output of PostGIS console is garbled

Deploy the flask environment using the pagoda panel

'coach, I want to play basketball!'—— AI Learning Series booklet for system students
随机推荐
Flex & bison start
How to convert data in cell cell into data in matrix
Introduction to basic knowledge of C language (Daquan) [suggestions collection]
Sword finger offer 06.24.35 Linked list
When drawing with origin, capital letter C will appear in the upper left corner of the chart. The removal method is as follows:
【使用yarn运行报错】The engine “node“ is incompatible with this module.
Sectigo的IP证书申请流程
MySQL master-slave replication and read-write separation
Naacl2022: (code practice) good visual guidance promotes better feature extraction, multimodal named entity recognition (with source code download)
Complete diagram / Euler loop
Build your own PE manually from winpe of ADK
Can wptx64 be uninstalled_ Which software of win10 can be uninstalled
Atcoder bit operation & Conclusion + formula derivation
一个快速切换一个底层实现的思路分享
Difference between classification and regression
transformers DataCollatorWithPadding类
MySQL主从复制与读写分离
MHA high availability coordination and failover
Intellij IDEA--格式化SQL文件的方法
Electron