Question
I wrote this program and i need to now how to find the points with the largest and smallest values of X and Y #include
I wrote this program and i need to now how to find the points with the largest and smallest values of X and Y
#include
double dis(int x, int y) { return x*x + y*y; } int main() { int x[100], y[100], n, temp; fstream in; in.open ("input.txt"); in >> n; for (int i = 0; i < n; i++) { in >> x[i]; in >> y[i]; cout << "(" << x[i] << "," << y[i] << ")" << endl; } for (int i = 0; i < n-1; i++) for (int j = i+1; j < n; j++) { if (dis(x[i], y[i]) > dis(x[j], y[j])) { temp = x[i]; x[i] = x[j]; x[j] = temp; temp = y[i]; y[i] = y[j]; y[j] = temp; } } cout << endl; for (int i = 0; i < n; i++) {
cout << "(" << x[i] << "," << y[i] << ")" << endl; }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started