Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include <stdio.

h>
#include <math.h>

void main()
{
float x[3],y[3];
double r,root1,root2;
double divisor,a,b,c;
printf("Enter the coodinates of GPS 1");
scanf("%f %f",&x[1],&y[1]);
printf("Enter the coodinates of GPS 2");
scanf("%f %f",&x[2],&y[2]);
divisor=((y[2]*y[2])-(2*y[2]*y[1])+(y[1]*y[1]));
r=sqrt(((x[2]-x[1])*(x[2]-x[1]))-((y[2]-y[1])*(y[2]-y[1])));
a=(1+((x[2]*x[2])-(2*x[2]*x[1])+(x[1]*x[1])/divisor));
b=((-2)*(y[1]))+((-(2*x[2]*x[2]*y[1])+(4*x[2]*x[1]*y[1])-(2*x[1]*x[1]*y[1]))/
(divisor));
c=((y[1]*y[1])-(r*r)+(((x[2]*x[2]*y[1]*y[1])-(2*x[2]*x[1]*y[1]*y[1])+
(x[1]*x[1]*y[1]*y[1]))/divisor));
root1 =(-b+(sqrt((b*b)-4*a*c)))/(2*a);
root2 =(-b-(sqrt((b*b)-4*a*c)))/(2*a);
if ((y[2]-root1)<=(y[2]-root2))
y[0]= root1;
else
y[0]= root2;
printf("the result latitude is %f",&y[0]);
x[0]= (x[1]+((x[2]-x[1])*((y[0]-y[1])/(y[2]-y[1]))));
printf("the longitude result is %f",&x[0]);
}

You might also like