Pages

Write a program in C# and find the value of final velocity by using Vf=Vi+at using methods.

Solution:

Pseudo Code:

  1. Initialize variable "vi"  (this will hold initial velocity value) 
  2. Initialize variable "t" to (this will hold time value) 
  3. Print message on console to ask user to input Initial velocity.
  4. Read user's input and convert to Double and store that input into variable "vi" that is necessary for velocity formula.
  5. Print message on console to ask user to input Time.
  6. Read user's input and convert to Double and store that input into variable "t" that is necessary for velocity formula.
  7. create a separate function "calculateFinalVelocity" that will calculate velocity on the basis of initial velocity and time values and will return the final velocity, then  call "calculateFinalVelocity(vi,t)" function and pass "vi" and "t".  
  8. Print the return value of  on console to show the final velocity...

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication20
 {
class myclass
    {
        public double  calculateFinalVelocity(double  vi,double t)
        {
            double vf =  vi+t*9.98;
            return vf;
        }
        static void Main(string[] args)
        {
            double vi,t;
            Console.WriteLine("plz enter the initial velocity");
            vi=Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("plz enter the time ");
            t= Convert.ToDouble(Console.ReadLine());
            myclass m = new myclass();
         
          Console.WriteLine("the the final velocity is {0}",m.calculateFinalVelocity(vi,t));
        }
        
    }

}

Output:


No comments:

Post a Comment