#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,j,n,i1,j1;
float x[10],y[10],max=-1000,d[10][10];
clrscr();
printf("Enter n the number of points: ");
scanf("%d",&n);
printf("Enter Coordinate of n points: ");
for(i=0;i<n;i++)
{
scanf("%f%f",&x[i],&y[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
d[i][j]=sqrt((x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i]));
}
printf("\nDistance table: \n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("%0.2f ",d[i][j]);
}
printf("\n");
}
max=-1000;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if ((d[i][j])>max && (j!=i))
{
max=d[i][j];
i1=i;
j1=j;
}
}
}
printf("\nMaximum Distance is %f \n",max);
printf("\nThe Point [%f %f] is nearest to point [%f %f] ",x[i1],y[i1],x[j1],y[j1]);
getch();
}
//Output
Enter n the number of points: 5
Enter Coordinate of n points: 0 2
2 4
4 3
4 1
2 5
Distance table:
0.00 2.83 4.12 4.12 3.61
2.83 0.00 2.24 3.61 1.00
4.12 2.24 0.00 2.00 2.83
4.12 3.61 2.00 0.00 4.47
3.61 1.00 2.83 4.47 0.00
Maximum Distance is 4.472136
The Point [4.000000 1.000000] is nearest to point [2.000000 5.000000]
#include<conio.h>
#include<math.h>
void main()
{
int i,j,n,i1,j1;
float x[10],y[10],max=-1000,d[10][10];
clrscr();
printf("Enter n the number of points: ");
scanf("%d",&n);
printf("Enter Coordinate of n points: ");
for(i=0;i<n;i++)
{
scanf("%f%f",&x[i],&y[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
d[i][j]=sqrt((x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i]));
}
printf("\nDistance table: \n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("%0.2f ",d[i][j]);
}
printf("\n");
}
max=-1000;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if ((d[i][j])>max && (j!=i))
{
max=d[i][j];
i1=i;
j1=j;
}
}
}
printf("\nMaximum Distance is %f \n",max);
printf("\nThe Point [%f %f] is nearest to point [%f %f] ",x[i1],y[i1],x[j1],y[j1]);
getch();
}
//Output
Enter n the number of points: 5
Enter Coordinate of n points: 0 2
2 4
4 3
4 1
2 5
Distance table:
0.00 2.83 4.12 4.12 3.61
2.83 0.00 2.24 3.61 1.00
4.12 2.24 0.00 2.00 2.83
4.12 3.61 2.00 0.00 4.47
3.61 1.00 2.83 4.47 0.00
Maximum Distance is 4.472136
The Point [4.000000 1.000000] is nearest to point [2.000000 5.000000]
No comments:
Post a Comment