Friday, March 21, 2014

Method_Ex_6 (Wk-8) Feb 24-28, 2014

Q; Write a method to compute Kinetic Energy (KE). 




m is mass in kilogram. v is speed in meters per second.
Provide the method with its required input. Then return the kinetic energy.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Method_6
{
    class Program
    {
        static void Main(string[] args)
        {
            double m, v;
            Console.Write("Enter mass in Kilogram: ");
            double.TryParse(Console.ReadLine(), out m);

            Console.Write("Enter speed in meter per sec: ");
            double.TryParse(Console.ReadLine(), out v);

            double kineticE = KineticEnergy(m, v);
            string Kenergy = String.Format("Kinetic Energy = {0:f2} joules", kineticE);
            DisplayResult(Kenergy);


            Console.ReadKey();
        }
        static double KineticEnergy(double m, double v)
        {
            //double ke = m * (v * v / 2);
            double ke = Math.Pow(v, 2);
            return ke;
        }
        static void DisplayResult(string s)
        {
            Console.WriteLine("\nvvvvvvvvvvvvvvvvvvvvvvvv");
            Console.WriteLine(s);
            Console.WriteLine("\n^^^^^^^^^^^^^^^^^^^^^^^^");
        }
    }
}



No comments:

Post a Comment