题目描述
读入三角形的三条边,进行如下的判断:
如果输入值不合法,输出 illegal triangle;
如果输入值合法,两条较短边的平方和大于最长边的平方,则输出 acute triangle,表示锐角三角形;
如果输入值合法,两条较短边的平方和等于最长边的平方,则输出 right triangle,表示直角三角形;
如果输入值合法,两条较短边的平方和小于最长边的平方,则输出 obtuse triangle,表示钝角三角形。
注意:如果两条短边的和大于第三边,那么这个三角形就是合法的
输入
输入三个整数 a,b,c(1≤a,b,c≤100),表示三角形的三条边。
输出
根据情况输出。
#include <stdio.h>
int main( ){
int a,b,c;
scanf("%d%d%d", &a, &b, &c);
int long1 = (a>b?a:b)>c?(a>b?a:b):c;
if (long1 == a){
if (b + c <= a) printf("illegal triangle");
else if( b * b + c * c > a * a) printf("acute triangle");
else if (b * b + c * c == a * a) printf("right triangle");
else printf("obtuse triangle");
}
else if(long1 == b){
if (a + c <= b) printf("illegal triangle");
else if( a * a + c * c > b * b) printf("acute triangle");
else if (a * a + c * c == b * b) printf("right triangle");
else printf("obtuse triangle");
}
else{
if (a + b <= c) printf("illegal triangle");
else if( b * b + a * a > c * c) printf("acute triangle");
else if (b * b + a * a == c * c) printf("right triangle");
else printf("obtuse triangle");
}
return 0;
}