当前位置:网站首页>详解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;
}希望能够帮到你,觉得有用的话就点赞支持一下吧!
边栏推荐
- Never use redis expired monitoring to implement scheduled tasks!
- ArcGIS secondary development -- arcpy batch automatic map publishing service
- Correlation of XOR / and
- Research on balloon problem
- K gold Chef (two conditions, two points and difference)
- 备战数学建模30-回归分析2
- Stream常用操作以及原理探索
- Common evaluation indexes of classification model -- confusion matrix and ROC curve
- Excerpt from three body
- BM3D in popular language
猜你喜欢

Electron

ThreadLocal giant pit! Memory leaks are just Pediatrics

Setup instance of layout manager login interface

量化框架backtrader之一文读懂observer观测器

ArcGIS batch export layer script

MySQL master-slave replication and read-write separation

Sword finger offer 21.57.58 I Double pointer (simple)

C language | Consortium

在云服务器中云磁盘如何挂载

Intellij IDEA--格式化SQL文件的方法
随机推荐
秒懂JSONArray和JSONObject的区别和使用
IP certificate application process of sectigo
Oracle ASMM和AMM
2022年最新贵州建筑八大员(机械员)模拟考试题库及答案
fileinput.js php,fileinput
Lucky numbers in the matrix
券商经理给的开户链接安全吗?找谁可以开户啊?
D - Face Produces Unhappiness
C语言基础知识入门(大全)「建议收藏」
Equation derivation: second order active bandpass filter design! (download: Tutorial + schematic + Video + code)
Extended hooks
'教练,我想打篮球!' —— 给做系统的同学们准备的 AI 学习系列小册
Transformers datacollatorwithpadding class
Electron
C language | Consortium
赠书 | 《认知控制》:我们的大脑如何完成任务?
Leaflet loading ArcGIS for server map layers
Knowledge about adsorption
Stream常用操作以及原理探索
2021-10-29 atcoder ABC157——B - Bingo