C++ Chapters

C++ Program to receive values of latitude and longitude in degress, of two places on earth and outputs the distance between them in nautical miles. The formula for distance in nautical is :
D=3963 cos-1 (sinL1sinL2+cosL1cosL2*cos(G2-G1))

Structure of C++ Programs - Overview
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    float L1, L2, G1, G2, D;
    
    cout << "Enter Two Values of Lattitude : ";
    cin >> L1 >> L2;
    
    cout << "\nEnter Two Values of Longitude : ";
    cin >> G1 >> G2;
    
    D = 3963 * acos(sin(L1) * sin(L2) + cos(L1) * cos(L2) * cos(G2 - G1));
    
    cout << "\n\nDistance is : " << D;
    
    return 0;
}

Output :
Enter Two Values of Lattitude : 50
100
Enter Two Values of Longitude : 150
200

Distance is : 1427.61

Leave a comment
Recent Comments
No Comments