25 lines
489 B
C
25 lines
489 B
C
|
#ifndef triangle_h
|
||
|
#define triangle_h
|
||
|
|
||
|
|
||
|
#include <stdlib.h>
|
||
|
#include <math.h>
|
||
|
#include "shape.h"
|
||
|
|
||
|
double triangleArea(Shape* triangle) {
|
||
|
double side = triangle->perimeter / 3;
|
||
|
double area = (sqrt(3) / 4) * (side * side);
|
||
|
return area;
|
||
|
}
|
||
|
|
||
|
Shape* newTriangle(double perimeter) {
|
||
|
Shape* triangle = malloc(sizeof(Shape));
|
||
|
triangle->numSides = 4;
|
||
|
triangle->perimeter = perimeter;
|
||
|
triangle->area = triangleArea;
|
||
|
return triangle;
|
||
|
}
|
||
|
|
||
|
#endif
|
||
|
|