Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main() {
- int N;
- do {
- cout << "Upisite N: ";
- cin >> N;
- }while(N <= 0);
- double polje[N][2];
- double d = 1000000; //udaljenost
- double pom = 0;
- double* tock1;
- double* tock2;
- /*
- int tock1;
- int tock2;
- */
- for(int i = 0; i < N; ++i) {
- cout << i+1 << " tocka, " << " x: ";
- cin >> polje[i][0];
- cout << i+1 << " tocka, " << " y: ";
- cin >> polje[i][1];
- }
- for(int i = 0; i < N-1; ++i) {
- for(int j = i+1; j < N; ++j) {
- pom = sqrt(pow(polje[j][0] - polje[i][0], 2) + pow(polje[j][1] - polje[i][1], 2));
- if(pom < d) {
- d = pom;
- tock1 = polje[i];
- tock2 = polje[j];
- /*
- int tock1 = i;
- int tock2 = j;
- */
- }
- }
- }
- cout << "Tocka 1: " << "\nx: " << tock1[0] << "\ny: " << tock1[1] << endl;
- cout << "Tocka 2: " << "\nx: " << tock2[0] << "\ny: " << tock2[1] << endl;
- cout << "Udaljenost: " << d;
- /*
- cout << "Tocka 1: " << "\nx: " << polje[tocka1][0] << "\ny: " << polje[tocka1][1] << endl;
- cout << "Tocka 2: " << "\nx: " << polje[tocka2][0] << "\ny: " << polje[tocka2][1] << endl;
- cout << "Udaljenost: " << d;
- +/
- }
Advertisement
Add Comment
Please, Sign In to add comment