using c++ to implement a class of trian gle
时间: 2024-05-11 13:15:08 浏览: 11
Sure! Here's an example implementation of a Triangle class in C:
```
#include <math.h>
struct Triangle {
double a;
double b;
double c;
};
double get_area(struct Triangle t) {
double s = (t.a + t.b + t.c) / 2;
return sqrt(s * (s - t.a) * (s - t.b) * (s - t.c));
}
int is_rightangled(struct Triangle t) {
double a2 = pow(t.a, 2);
double b2 = pow(t.b, 2);
double c2 = pow(t.c, 2);
return a2 + b2 == c2 || a2 + c2 == b2 || b2 + c2 == a2;
}
int main() {
struct Triangle t = {3, 4, 5};
printf("Triangle perimeter: %f\n", t.a + t.b + t.c);
printf("Triangle area: %f\n", get_area(t));
printf("Triangle is right-angled: %d\n", is_rightangled(t));
return 0;
}
```
Hope that helps! Let me know if you have any other questions.
相关推荐
![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)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)