Saturday, March 21, 2015

Compute the Radian on C pgm



#include
#include
 
float toRadian (float angle)
 {
  float const PI = atan(1.0)*4.0;
 
  return(angle * PI / 180.0);
}
 
float computeDist (float lat1, float long1, float lat2, float long2) 
{
  float const R = 3964.0;
  float temp;
 
  temp = sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(long1-long2);
  return(2.0 * R * atan(sqrt((1.0-temp)/(1.0+temp))));
}
 
void main ()
 {
  float lat1, long1, lat2, long2, distance;
 
  cout << "Enter lat1, long1: ";
  cin >> lat1 >> long1;
  cout << "Enter lat2, long2: ";
  cin >> lat2 >> long2;
  distance = computeDist(toRadian(lat1), 
                                      toRadian(long1), 
                                      toRadian(lat2),
                                      toRadian(long2));
  cout << "Distance = " << distance << endl;
}

No comments:

Post a Comment