当前位置:网站首页>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 !
边栏推荐
猜你喜欢

这才是优美的文件系统挂载方式,亲测有效

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

年薪50万是一条线,年薪100万又是一条线…...

使用宝塔面板部署flask环境

Sword finger offer 06.24.35 Linked list

'coach, I want to play basketball!'—— AI Learning Series booklet for system students

The JVM outputs GC logs, causing the JVM to get stuck. I am stupid

登录认证服务

ArcGIS batch export layer script

Unity 利用Skybox Panoramic着色器制作全景图预览有条缝隙问题解决办法
随机推荐
Sword finger offer 05.58 Ⅱ string
Use abp Zero builds a third-party login module (I): Principles
国信证券的排名如何?办理股票开户安全吗?
Datasets dataset class (2)
Is the account opening link given by the broker manager safe? Who can I open an account with?
15 bs对象.节点名称.节点名称.string 获取嵌套节点内容
idea快捷键
【async/await】--异步编程最终解决方案
Complimentary Book Cognitive Control: how does our brain accomplish tasks?
Experience sharing of mathematical modeling: comparison between China and USA / reference for topic selection / common skills
The annual salary of 500000 is one line, and the annual salary of 1million is another line
(improved) bubble sorting and (improved) cocktail sorting
D - Face Produces Unhappiness
子查询的使用
ArcGIS batch export layer script
Recent important news
Atcoder bit operation & Conclusion + formula derivation
Excerpt from three body
K gold Chef (two conditions, two points and difference)
Electron