fork download
  1. #include <iostream>
  2. #include "math.h"
  3. using namespace std;
  4.  
  5. void alldist(int *x, int *y, int n)
  6. {
  7. float d;
  8. for (int i = 0; i < n-1; i++)
  9. {
  10. for (int j = i + 1; j < n; j++)
  11. {
  12. d = sqrt(pow((x[j] - x[i]), 2) + pow((y[j] - y[i]), 2));
  13. cout <<"dist "<< i << ":" << j << " " << d << " ";
  14. }
  15. cout << endl;
  16. }
  17. }
  18. int main() {
  19. int *x=new int [5] {1, 4, 6, 2, 1};
  20. int *y=new int [5] {6, 7, 8, 9, 10};
  21. alldist(x, y, 5);
  22. return 0;
  23. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
dist 0:1 3.16228 dist 0:2 5.38516 dist 0:3 3.16228 dist 0:4 4 
dist 1:2 2.23607 dist 1:3 2.82843 dist 1:4 4.24264 
dist 2:3 4.12311 dist 2:4 5.38516 
dist 3:4 1.41421