当前位置:网站首页>详解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;
}
希望能够帮到你,觉得有用的话就点赞支持一下吧!
边栏推荐
- 使用宝塔面板部署flask环境
- DOS command
- Sword finger offer 09.30 Stack
- Sword finger offer 06.24.35 Linked list
- Complete diagram / Euler loop
- Difference between classification and regression
- Practice with the topic of bit operation force deduction
- How to call self written functions in MATLAB
- IP certificate application process of sectigo
- Oracle ASMM and AMM
猜你喜欢
Sword finger offer 09.30 Stack
ArcGIS cannot be opened and displays' because afcore cannot be found ' DLL, solution to 'unable to execute code'
Correlation of XOR / and
Related knowledge of libsvm support vector machine
Codeforces Global Round 21A~D
VMware partial settings
Sword finger offer 45.61 Sort (simple)
How to personalize VIM editor format (DIY)
Freefilesync folder comparison and synchronization software
【使用yarn运行报错】The engine “node“ is incompatible with this module.
随机推荐
fileinput.js php,fileinput
Online bull Blogger
Never use redis expired monitoring to implement scheduled tasks!
在云服务器中云磁盘如何挂载
'教练,我想打篮球!' —— 给做系统的同学们准备的 AI 学习系列小册
Experience sharing of mathematical modeling: comparison between China and USA / reference for topic selection / common skills
Pychar remotely connects to the server to run code
Extended hooks
Combat readiness mathematical modeling 31 data interpolation and curve fitting 3
Related knowledge of libsvm support vector machine
Common controls and custom controls
Installation tutorial about origin2019
Introduction to granular computing
Difference between classification and regression
Build your own PE manually from winpe of ADK
秒懂JSONArray和JSONObject的区别和使用
Correlation of XOR / and
Gartner 2022 Top Strategic Technology Trends Report
【使用yarn运行报错】The engine “node“ is incompatible with this module.
A solution to the problem that the display of newff function in neural network cannot be converted from double to struct