Habsburg

4

Jun 23rd, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. float funUd(float x1, float y1, float x2, float y2) {
  6.     return sqrt((pow(x2-x1,2)) + (pow(y2-y1,2)));
  7. }
  8.  
  9. void fun1(int N, float polje[][2]) {
  10.     float minUd = 1000000;
  11.     float num = 0;
  12.     int pos[2];
  13.     for(int i = 0; i < (N - 1); i++) {
  14.         for(int j = i + 1; j < N; j++) {
  15.             num = funUd(polje[i][0], polje[i][1], polje[j][0], polje[j][1]);
  16.             if(num < minUd) {
  17.                 minUd = num;
  18.                 pos[0] = i;
  19.                 pos[1] = j;
  20.             }
  21.         }
  22.     }
  23.     cout << polje[pos[0]][0] << " " << polje[pos[0]][1] << endl << polje[pos[1]][0] << " " << polje[pos[1]][1] << endl << minUd << endl;
  24.    
  25. }
  26.  
  27. int main() {
  28.     int N;
  29.     do {
  30.         cout << "upisite broj N: ";
  31.         cin >> N;
  32.     }while(N <= 0);
  33.    
  34.     float polje[N][2];
  35.    
  36.     for(int i = 0; i < N; i++) {
  37.         cout << "Upisite prvi broj: ";
  38.         cin >> polje[i][0];
  39.         cout << "Upisite drugi broj: ";
  40.         cin >> polje[i][1];
  41.     }
  42.     fun1(N, polje);
  43.    
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment