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))

Types - C# Language Fundamentals
using System;

public class Program
{
    public static void Main()
    {
        Double L1, L2, G1, G2, D;

        Console.Write("Enter Two Values of Lattitude : ");
        L1 = Convert.ToDouble(Console.ReadLine());
        L2 = Convert.ToDouble(Console.ReadLine());
        
        Console.Write("\nEnter Two Values of Longitude : ");
        G1 = Convert.ToDouble(Console.ReadLine());
        G2 = Convert.ToDouble(Console.ReadLine());
        
        D = 3963 * Math.Acos(Math.Sin(L1) * Math.Sin(L2) + Math.Cos(L1) * Math.Cos(L2) * Math.Cos(G2 - G1));
        
        Console.Write("\n\nDistance is : " + D);
    }
}

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

Distance is : 1427.61183890595

Leave a comment
Recent Comments
No Comments