Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- float funUd(float x1, float y1, float x2, float y2) {
- return sqrt((pow(x2-x1,2)) + (pow(y2-y1,2)));
- }
- void fun1(int N, float polje[][2]) {
- float minUd = 1000000;
- float num = 0;
- int pos[2];
- for(int i = 0; i < (N - 1); i++) {
- for(int j = i + 1; j < N; j++) {
- num = funUd(polje[i][0], polje[i][1], polje[j][0], polje[j][1]);
- if(num < minUd) {
- minUd = num;
- pos[0] = i;
- pos[1] = j;
- }
- }
- }
- cout << polje[pos[0]][0] << " " << polje[pos[0]][1] << endl << polje[pos[1]][0] << " " << polje[pos[1]][1] << endl << minUd << endl;
- }
- int main() {
- int N;
- do {
- cout << "upisite broj N: ";
- cin >> N;
- }while(N <= 0);
- float polje[N][2];
- for(int i = 0; i < N; i++) {
- cout << "Upisite prvi broj: ";
- cin >> polje[i][0];
- cout << "Upisite drugi broj: ";
- cin >> polje[i][1];
- }
- fun1(N, polje);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment