Computer Science, asked by sayalidoshi315, 14 days ago

write a program to print larger of x and y coordinates of a given point .​

Answers

Answered by juwairiyahimran18
3

Coordinates of rectangle with given points lie inside

Given two arrays X[] and Y[] with n-elements, where (Xi, Yi) represent a point on coordinate system, find the smallest rectangle such that all points from given input lie inside that rectangle and sides of rectangle must be parallel to Coordinate axis. Print all four coordinates of an obtained rectangle.

Note: n >= 4 (we have at least 4 points as input).

Examples :

Input : X[ ] = {1, 3, 0, 4}, y[ ] = {2, 1, 0, 2}

Output : {0, 0}, {0, 2}, {4, 2}, {4, 0}

Input : X[ ] = {3, 6, 1, 9, 13, 0, 4}, Y[ ]= {4, 2, 6, 5, 2, 3, 1}

Output : {0, 1}, {0, 6}, {13, 6}, {13, 1}

C++ Program to find smallest rectangle and to conquer all points.

using namespace std;

// function to print coordinate of smallest rectangle

void printRect(int X[], int Y[], int n)

{

// find Xmax and Xmin

int Xmax = *max_element(X, X + n);

int Xmin = *min_element(X, X + n);

// find Ymax and Ymin

int Ymax = *max_element(Y, Y + n);

int Ymin = *min_element(Y, Y + n);

// print all four coordinates

cout << "{" << Xmin << ", " << Ymin << "}" << endl;

cout << "{" << Xmin << ", " << Ymax << "}" << endl;

cout << "{" << Xmax << ", " << Ymax << "}" << endl;

cout << "{" << Xmax << ", " << Ymin << "}" << endl;

}

// driver program

int main()

{

int X[] = { 4, 3, 6, 1, -1, 12 };

int Y[] = { 4, 1, 10, 3, 7, -1 };

int n = sizeof(X) / sizeof(X[0]);

printRect(X, Y, n);

return 0;

}

Output:

{-1, -1}

{-1, 10}

{12, 10}

{12, -1}

hopefully its helped u dear :)

(if my answer not relevant to ur question then u can report... thnku)

#keepsmiling❤✌

Similar questions