I am trying to make a program that makes the user input a pairs of xy coordinates. The program must use the three farthest points from (0,0) as the vertices of the triangle. The program must output the area of the triangle. I know the formula for it but i am having trouble in getting the three farthest points from (0,0).
Here I have the code for sorting only the x coordinates in ascending order. How do I sort the pairs and get the three farthest points? Or is there any better way to make this program?
int main() {
int x, a, b, t;
cin >> a; // a pairs of x and y
int xcoor[a], ycoor[a];
for (x = 1; x <= a; x++)
{
//enter coordinates
cin >> xcoor[x] >> ycoor[x];
}
for (x = 0; x < a; x++)
{
for (int y = 0; y < a - 1; y++)
{
if (xcoor[y] > xcoor[y + 1])
{
t = xcoor[y];
xcoor[y] = xcoor[y + 1];
xcoor[y + 1] = t;
}
}
}
return 0;
}