#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;
struct Titik{
int x, y;
};
void TitikTerdekat(Titik p[], int n, Titik &p1, Titik &p2){
double d,dmin,dmax,temp;
int i,j;
dmin=9999;
for(int i=1; i<=n; i++){
for(int j=i+1; j<=n; j++){
temp = sqrt( pow(( p[i].x - p[j].x ),2) + pow(( p[i].y - p[j].y ),2) );
if(d<dmin){
dmin=d;
p1=p[i];
p2=p[j];
}
}
}
}
int main(int argc, char *argv[]){
Titik p[100];
int n;
Titik p1,p2;
cout<<"Masukkan banyak titik : ";
cin>>n;
cout<<"Masukkan titik - titiknya : "<<endl;
for(int i=0; i<n; i++){
cout<<"Titik ["<<i+1<<"] : "<<endl;
cout<<"x : "; cin>>p[i].x;
cout<<"y : "; cin>>p[i].y;
}
TitikTerdekat(p,n,p1,p2);
cout<<endl;
cout<<"Dua titik terdekat : "<<endl;
cout<<"Titik pertama = ( "<<p1.x<<" , " <<p1.y<<" )"<<endl;
cout<<"Titik kedua = ( "<<p2.x<<" , " <<p2.y<<" )";
cout<<endl;
system("PAUSE");
return 0;
}
Senin, 19 Mei 2014
TITIK TERDEKAT C++
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar