自由尋覓快樂別人從沒法感受

0%

C语言学习第四章T7

题目:输入三个数,判断这三个数对应长度的线段构成的三角形是什么类型。设计数据并测试程序。

主要代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# include <stdio.h>
int maxiumn (int x,int y,int z);
int main (void)
{
int a,b,c;
printf("triangle's a line:");
scanf("%d",&a);
printf("triangle's b line:");
scanf("%d",&b);
printf("triangle's c line:");
scanf("%d",&c);
//input tri's 3 line
if (a<0 || b<0 || c<0)
{
printf("error!It's not a triangle!");
}
else
{
if (a+b<c || a+c<b || b+c<a) //judge if it's tri or not
{
printf("error! \n");
}
else
{
int mac,l1,l2;
mac=maxiumn(a,b,c);
if (mac==a) //judge the line from big to small
{
l1=b;
l2=c;
}
else if (mac==b)
{
l1=a;
l2=c;
}
else
{
l1=a;
l2=b;
}
if (l1*l1+l2*l2==mac*mac) //judge the shape of triangle
{
printf("it's a RT triangle \n");
}
else if (l1*l1+l2*l2<mac*mac)
{
printf("it's a acute angle triangle\n");
}
else
{
printf("it's an obtuse angle triangle\n");
}
}
}
return 0;
}

int maxiumn (int x,int y,int z) //count the longest line
{
int max;
if (x>y)
{
max=x;
}
else
{
max=y;
}
if (max<z)
{
max=z;
}
printf("the max line:%d \n",max);
return max;
}

运行结果: