You are given 3 sets of coordinates that form a triangle. Write code to find the area of the triangle enclosed by those coordinates.
For example, the 3 points have coordinates given as x = [0, 3, 6] and y = [0, 3, 0], aligned by index, so the 3 coordinates are [0,0], [3,3], [6,0]. The height of the triangle is 3, and the width is 6, so the area of the triangle is 6 * 3 / 2 = 9. All resulting areas will be whole numbers. Not all triangles will contain a right angle.
Function Description
Complete the function getTriangleArea in the editor below. The function must return an integer which indicates the area of the triangle.
getTriangleArea has the following parameter(s):
x: An integer array, that
denotes the x coordinates.
y: An integer array, that
denotes the y coordinates.
Constraints
- 1
≤ x[i] < 100000
- 1
≤ y[i] ;< 100000
Input Format For Custom Testing
Input from stdin will be processed as follows and passed to the
function:
The first line gives the number of x coordinates (always 3).
No comments:
Post a Comment