1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include<stdio.h>
double distancefromhometooffice (double hx, double hy, double ox, double oy);
double distancefromofficetoNTUC (double ox, double oy, double nx, double ny);
double distancefromNTUCtohome (double hx, double hy, double nx, double ny);
int main()
{
double hx, hy, ox, oy, nx, ny;
printf("Please enter the coordinates for home", hx, hy);
scanf("%lf %lf", &hx, &hy);
printf("Please enter the coordinate for office", ox, oy);
scanf("%lf %lf", &ox, &oy);
printf("Please enter the coordinate for NTUC", nx, ny);
scanf("%lf %lf", &nx, &ny);
double Distance1= distancefromhometooffice(hx, hy, ox, oy);
printf("%lf", Distance1);
double Distance2= distancefromofficetoNTUC(ox, oy, nx, ny);
printf("%lf", Distance2);
double Distance3= distancefromNTUCtohome(hx, hy, nx, ny);
printf("%lf", Distance3);
double totalDistance= totaldistancetravelled(Distance1, Distance2, Distance3);
printf("%lf", totalDistance);
return 0;
}
double distancefromhometooffice (double hx, double hy, double ox, double oy)
{
double Distance1;
Distance1= sqrt( (hx-ox)*(hx-ox) + (hy-oy)(hy-oy) );
return Distance1;
}
double distancefromofficetoNTUC (double ox, double oy, double nx, double ny)
{
double Distance2;
Distance2= sqrt( (nx-ox)*(nx-ox) + (ny-oy)(ny-oy) );
return Distance2;
}
double distancefromNTUCtohome (double hx, double hy, double nx, double ny)
{
double Distance3;
Distance3= sqrt( (nx-hx)*(nx-hx) + (ny-hy)(ny-hy) );
return Distance3;
}
double totaldistancetravelled (double Distance1, double Distance2, double Distance3)
{
double totalDistance;
totalDistance= Distance1 + Distance2 + Distance3;
return totalDistance;
}
|