当前位置:网站首页>Detailed explanation of C language programming problem: can any three sides form a triangle, output the area of the triangle and judge its type
Detailed explanation of C language programming problem: can any three sides form a triangle, output the area of the triangle and judge its type
2022-06-26 14:48:00 【Wake up and study】
problem : Judge whether the triangle can be formed according to the three sides of the input triangle , If you can , Then output its area and judge the type of the triangle .
Ideas :
1、 Judge whether three sides can form a triangle : The sum of any two sides is greater than the third 、 The difference between any two sides is less than the third side .( Here is an example of the former )
2、 The triangle area formula ( Helen's formula is used here ): Half circumference
Triangle area 
3、 The type of triangle : Equilateral triangle 、 an isosceles triangle 、 right triangle 、 General triangle
Code :
#include <stdio.h>
#include <math.h>
int main()
{
float a, b, c;// Define the three sides of a triangle as a、b、c
float p, S;// Define the half circumference of a triangle p、 area S
scanf("%f,%f,%f",&a, &b, &c);// Enter any three sides
if ((a+b>c) && (a+c>b) &&(b+c>a))// The sum of any two sides of a triangle is greater than the third
{
p = (a + b + c) / 2;// Half circumference
S = sqrt(p * (p - a) * (p - b) * (p - c));
printf(" The area of the triangle is : % f\n", S);
if ((a==b) && (b==c))// Three sides equal
printf(" Equilateral triangle \n");
else if ((a==b)||(b==c)||(a==c))// Any two sides are equal
printf(" an isosceles triangle \n");
else if ((a * a + b * b == c * c) || (a * a + c * c == b * b) || (c * c + b * b == a * a))// Pythagorean theorem
printf(" right triangle \n");
else printf(" General triangle \n");
}
else printf(" Cannot form a triangle \n");
return 0;
}I hope I can help you , If you think it's useful, just praise and support it !
边栏推荐
- Login authentication service
- BM3D in popular language
- Two dimensional DFS
- 详解C语言编程题:任意三条边能否构成三角形,输出该三角形面积并判断其类型
- The JVM outputs GC logs, causing the JVM to get stuck. I am stupid
- VMware partial settings
- Sword finger offer 15.65.56 I 56Ⅱ. Bit operation (simple - medium)
- 备战数学建模30-回归分析2
- SwiftUI找回丢失的列表视图(List)动画
- 15 bs对象.节点名称.节点名称.string 获取嵌套节点内容
猜你喜欢

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

MySQL master-slave replication and read-write separation

vmware部分设置

Mathematical modeling of war preparation 30 regression analysis 2
![[solo π] ADB connects multiple mobile phones](/img/44/4bd88725434fb67c9237645f024071.png)
[solo π] ADB connects multiple mobile phones

Sword finger offer 40.41 Sort (medium)

'教练,我想打篮球!' —— 给做系统的同学们准备的 AI 学习系列小册

使用宝塔面板部署flask环境

从Celsius到三箭:加密百亿巨头们的多米诺,史诗级流动性的枯竭

Correlation of XOR / and
随机推荐
Eigen(3):error: ‘Eigen’ has not been declared
STM32F1和GD32F1有什么区别?
Sword finger offer 21.57.58 I Double pointer (simple)
备战数学建模31-数据插值与曲线拟合3
BM3D in popular language
Intellij IDEA--格式化SQL文件的方法
MHA high availability coordination and failover
备战数学建模32-相关性分析2
Online bull Blogger
一篇抄十篇,CVPR Oral被指大量抄袭,大会最后一天曝光!
工作上对金额价格类小数点的总结以及坑
Can wptx64 be uninstalled_ Which software of win10 can be uninstalled
Excerpt from three body
MHA高可用配合及故障切换
备战数学建模30-回归分析2
Flex & bison start
Complete diagram / Euler loop
Caelus - full scene offline mixed Department solution
Knowledge about the determination coefficient R2 and the relationship with the correlation coefficient
年薪50万是一条线,年薪100万又是一条线…...