Coordinates of rectangle with given points lie inside | Program to find smallest rectangle to conquer all points ; function to print coordinate of smallest rectangle ; find Xmax and Xmin ; find Ymax and Ymin ; print all four coordinates ; driver program
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printRect ( int X [ ] , int Y [ ] , int n ) { int Xmax = * max_element ( X , X + n ) ; int Xmin = * min_element ( X , X + n ) ; int Ymax = * max_element ( Y , Y + n ) ; int Ymin = * min_element ( Y , Y + n ) ; cout << " { " << Xmin << " , ▁ " << Ymin << " } " << endl ; cout << " { " << Xmin << " , ▁ " << Ymax << " } " << endl ; cout << " { " << Xmax << " , ▁ " << Ymax << " } " << endl ; cout << " { " << Xmax << " , ▁ " << Ymin << " } " << endl ; } 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 ; }