问题描述:
设计函数int judgeTriangle(int a,int b,int c),判断a、b、c三边是否能构成三角形,如果能,那么进一步判断是属于哪种三角形(等边、等腰、直角、不规则三角形)。这里的a、b、c没有顺序之分。
当a、b、c三边不能构成三角形时,返回-1;当a、b、c三边构成不规则三角形时,返回0;当a、b、c三边构成直角三角形时,返回1;当a、b、c三边构成等腰三角形时,返回2;当a、b、c三边构成等边三角形时,返回3。
输入与输出要求:
输入三个正整数a、b、c,分别代表三角形的三边,输出判断结果。当无法构成三角形时输出“It is not a triangle.”;当构成不规则三角形时输出“It is a scalenous triangle.”;当构成直角三角形时输出“It is a right-angled triangle.”;当构成等腰三角形时输出“It is an isosceles triangle.”;当构成等边三角形时输出“It is a equilateral triangle.”。
程序运行效果:
Sample 1:
13 5 12↙
It is a right-angled triangle.
Sample 2:
5 5 5↙
It is a equilateral triangle.
Sample 3:
8 1 8↙
It is an isosceles triangle.
Sample 4:
1 6 5↙
It is not a triangle.
Sample 5:
3 6 5↙
It is a scalenous triangle.
#include<stdio.h>
int main(){
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(a+b<=c||a+c<=b||b+c<=a) printf("It is not a triangle.\n");
else if(a*a+b*b==c*c||a*a+c*c==b*b||a*a==b*b+c*c) printf("It is a right-angled triangle.\n");
else if(a==b&&b==c) printf("It is a equilateral triangle.\n");
else if(a==b||b==c||a==c) printf("It is an isosceles triangle.\n");
else printf("It is a scalenous triangle.\n");
return 0;
}