Saturday, 2 December 2017

C# Program to Perform Conversions of Meter to Kilometer and viceversa


Code:

using System;
class Program
{
    static void Main()
    {
        double m1 = 200;
        Console.WriteLine("Meter   ::    Kilometer");
        double k1 = ConvertDistance.cMtK(m1);
        Console.WriteLine("{0}     ::    {1}", m1, k1);
        double m4 = 3107;
        double k4 = ConvertDistance.cMtK(m4);
        Console.WriteLine("{0}   ::     {1}", m4, k4);
        double k3 = 5.1;
        Console.WriteLine();
        Console.WriteLine("Kilometer     ::     Meter");
        double m3 = ConvertDistance.cKtM(k3);
        Console.WriteLine("{0}           ::     {1}", k3, m3);
        double k2 = 3.219;
        double m2 = ConvertDistance.cKtM(k2);
        Console.WriteLine("{0}         ::    {1}", k2, m2);
        Console.Read();
    }
}

public static class ConvertDistance
{
    public static double cMtK(double meters)
    {
        return meters / 1000;
    }

    public static double cKtM(double kilometers)
    {
        return kilometers * 1000;
    }
}


Output:

Meter  ::  Kilometer
200    ::  0.200000
3107  ::  3.107

Kilometer ::  Meter
5.1       ::  5100
3.219     ::  3219


More C# Programs:





















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...