用c++语言设计Triangle类,用于判断所输入的三角形的三条边能否组成三角形,以及三角形的类型
时间: 2024-05-20 20:18:21 浏览: 20
#include <stdio.h>
typedef struct {
int a;
int b;
int c;
} Triangle;
int is_triangle(Triangle t) {
if (t.a + t.b > t.c && t.a + t.c > t.b && t.b + t.c > t.a) {
return 1;
}
return 0;
}
void print_type(Triangle t) {
if (t.a == t.b && t.b == t.c) {
printf("Equilateral triangle\n");
} else if (t.a == t.b || t.a == t.c || t.b == t.c) {
printf("Isosceles triangle\n");
} else {
printf("Scalene triangle\n");
}
}
int main() {
Triangle t;
printf("Enter the three sides of the triangle:\n");
scanf("%d %d %d", &t.a, &t.b, &t.c);
if (is_triangle(t)) {
printf("This is a triangle.\n");
print_type(t);
} else {
printf("This is not a triangle.\n");
}
return 0;
}
相关推荐
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)