Enter the Speed(km/hr) : 5 Enter the Time(hrs) : 4 Distance Travelled (kms) : 20
This is a C# Program to calculate the distance travelled by reading speed and time.
This C# Program Calculates the Distance Travelled by Reading Speed and Time.
Here distance is calculated by multiplying speed and time.
Here is source code of the C# Program to Calculate the Distance Travelled by Reading Speed and Time. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Calculate the Distance Travelled by Reading Speed and Time */ using System; class program { public static void Main() { int speed, distance, time; Console.WriteLine("Enter the Speed(km/hr) : "); speed = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter the Time(hrs) : "); time = Convert.ToInt32(Console.ReadLine()); distance = speed * time; Console.WriteLine("Distance Travelled (kms) : " + distance); Console.ReadLine(); } }
In this C# program, library function defined in <math.h> header file is used. We are reading the Speed(km/hr) and the time(hrs) using ‘speed’ and ‘time’ variables respectively. The following formula is used to compute the distance
Enter the Speed(km/hr) : 5 Enter the Time(hrs) : 4 Distance Travelled (kms) : 20