最近对问题:
#include<stdio.h>
void ClosestPoints(int x[],int y[],int n){
int index1,index2;
int d,minDist=1000;
int i,j;
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++){
d=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
if(d<minDist)
{
minDist=d;
index1=i;
index2=j;
}
}
printf("最近的点坐标是%d&&%d个\n",index1+1,index2+1);
printf("最近距离%d\n",minDist);
}
void main(){
int x[4]={5,12,3,2};
int y[4]={3,14,2,8};
ClosestPoints(x,y,4);
}
运行结果: