导航

 1 #include <stdio.h>
 2 
 3 //判断是否是三角形
 4 void judgeTriangle(float a,float b,float c)
 5 {
 6     //验证边与边的关系
 7     if( (a + b > c) && (a + c > b) && (b + c > a) )
 8     {
 9         printf("It's a triangle!\n\n") ;
10     }
11     else
12     {
13         printf("It's not a triangle!\n\n") ;
14     }
15 }
16 
17 int main(void)
18 {
19     float n1, n2, n3;
20     while(1)
21     {
22         //输入三边的值
23         printf("Please input 3 numbers : \n") ;
24         scanf("%f %f %f",&n1, &n2, &n3) ;
25         
26         //判断三边是否都大于0,否则退出程序
27         if( (n1 > 0) && (n2 > 0) && (n3 > 0) )
28         {
29             judgeTriangle(n1,n2,n3) ;
30         }
31         else break ;
32     }
33     return 0 ;
34 }