Habsburg

cetvrti

Apr 20th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main() {
  6.     int N;
  7.     do {
  8.         cout << "Upisite N: ";
  9.         cin >> N;
  10.     }while(N <= 0);
  11.    
  12.     double polje[N][2];
  13.    
  14.     double d = 1000000; //udaljenost
  15.     double pom = 0;
  16.    
  17.     double* tock1;
  18.     double* tock2;
  19.    
  20.     /*
  21.     int tock1;
  22.     int tock2;
  23.    
  24.     */
  25.     for(int i = 0; i < N; ++i) {
  26.         cout << i+1 << " tocka, " << " x: ";
  27.         cin >> polje[i][0];
  28.         cout << i+1 << " tocka, " << " y: ";
  29.         cin >> polje[i][1];
  30.     }
  31.    
  32.     for(int i = 0; i < N-1; ++i) {
  33.         for(int j = i+1; j < N; ++j) {
  34.             pom = sqrt(pow(polje[j][0] - polje[i][0], 2) + pow(polje[j][1] - polje[i][1], 2));
  35.             if(pom < d) {
  36.                 d = pom;
  37.                 tock1 = polje[i];
  38.                 tock2 = polje[j];
  39.                 /*
  40.                 int tock1 = i;
  41.                 int tock2 = j;
  42.                 */
  43.             }
  44.         }
  45.     }
  46.     cout << "Tocka 1: " << "\nx: " << tock1[0] << "\ny: " << tock1[1] << endl;
  47.     cout << "Tocka 2: " << "\nx: " << tock2[0] << "\ny: " << tock2[1] << endl;
  48.     cout << "Udaljenost: " << d;
  49.    
  50.     /*
  51.     cout << "Tocka 1: " << "\nx: " << polje[tocka1][0] << "\ny: " << polje[tocka1][1] << endl;
  52.     cout << "Tocka 2: " << "\nx: " << polje[tocka2][0] << "\ny: " << polje[tocka2][1] << endl;
  53.     cout << "Udaljenost: " << d;
  54.     +/
  55. }
Advertisement
Add Comment
Please, Sign In to add comment