using c++ to implement a class of trian gle
时间: 2024-05-08 19:19:17 浏览: 14
Sure! Here is an example of how to implement a class of triangle using C:
```
#include <stdio.h>
#include <stdlib.h>
struct Triangle {
int side1;
int side2;
int side3;
};
int main() {
struct Triangle t;
printf("Enter the sides of the triangle: ");
scanf("%d %d %d", &t.side1, &t.side2, &t.side3);
if(t.side1 + t.side2 > t.side3 && t.side2 + t.side3 > t.side1 && t.side1 + t.side3 > t.side2) {
printf("The triangle is valid!\n");
printf("The perimeter of the triangle is %d\n", t.side1+t.side2+t.side3);
} else {
printf("The triangle is invalid.\n");
}
return 0;
}
```
Hope this helps!
相关问题
using c++ to implement a class of triangle
Sure, to implement a class of triangle in C, you can create a structure for the triangle with three variables for the three sides, and then define functions for computing the perimeter, area, and angles of the triangle. The functions can use the formulae for calculating these quantities based on the sides of the triangle.
Using c++ to implement a class of Triangle.
Sure, I can help you with that! Creating a class for Triangle in C is fairly simple. You'll need to define the class with three properties for the three sides of the triangle and some methods to calculate its area and perimeter. Is there anything specific you need help with?