Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. typedef struct point point;
  4.  
  5. struct point {
  6.    int x;
  7.    int y;
  8.    int z; };
  9.    
  10. void fnc(struct point arr[], int k, int *w1,int *w2)
  11. {int i, j;
  12. double dist, t;
  13. for(i=0; i<k-1 ;i++){
  14.     for (j=i+1; j<k;j++){
  15.         if((t=sqrt(
  16.         pow((arr[j].x - arr[i].x), 2)+
  17.         pow((arr[j].y - arr[i].y), 2)+
  18.         pow((arr[j].z - arr[i].z), 2) ))>dist){
  19.             dist = t;
  20.             printf("dist %lf i:%d j:%d\n",dist,i,j);
  21.             *w1=i;
  22.             *w2=j;
  23.         }
  24.         }          
  25.     }  
  26. }
  27. int main ()
  28. {
  29. int w1,w2 ;
  30. struct point arr[7] =
  31. {
  32. {1,2,3},
  33. {3,5,7},
  34. {4,2,3},
  35. {5,1,7},
  36. {6,2,3},
  37. {1,6,3},
  38. {1,5,3}
  39. };
  40. fnc(arr,7,&w1,&w2);
  41. printf("najdalsze punkty to %d %d",w1,w2);
  42.  
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement