
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Coordinates of rectangle with given points lie inside in C++
In this tutorial, we will be discussing a program to find the coordinates of rectangle
with given points lying inside.
For this we will be provided with some coordinate points. Our task is to find the smallest rectangle such that all the points lie inside it and it should have its sides parallel to the coordinate axis.
Example
#include <bits/stdc++.h> using namespace std; //calculating the coordinates of smallest rectangle void print_rectangle(int X[], int Y[], int n){ //finding minimum and maximum points 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]); print_rectangle(X, Y, n); return 0; }
Output
{-1, -1} {-1, 10} {12, 10} {12, -1}
- Related Articles
- Find minimum area of rectangle with given set of coordinates in C++
- Queries on count of points lie inside a circle in C++
- Count the number of rhombi possible inside a rectangle of given size in C++
- C program to find in which quadrant the coordinates lie.
- Generate a Pseudo-Vandermonde matrix of given degree with float array of points coordinates in Python
- Generate a Pseudo-Vandermonde matrix of given degree with complex array of points coordinates in Python
- Maximum area of rectangle possible with given perimeter in C++
- Find Corners of Rectangle using mid points in C++
- C++ Program to Check if a Given Set of Three Points Lie on a Single Line or Not
- How To Check if a Given Point Lies Inside a Rectangle in Java?
- Possible number of Rectangle and Squares with the given set of elements in C++
- Count BST subtrees that lie in given range in C++
- Find minimum radius such that atleast k point lie inside the circle in C++
- Count BST nodes that lie in a given range in C++
- Generate pseudo Vandermonde matrix of Chebyshev polynomial with float array of points coordinates in Python

Advertisements