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
Distance = Speed * Time
Enter the Speed(km/hr) : 5 Enter the Time(hrs) : 4 Distance Travelled (kms) : 20
Sanfoundry Global Education & Learning Series – 1000 C# Programs.
- Get Free Certificate of Merit in C# Programming
- Participate in C# Programming Certification Contest
- Become a Top Ranker in C# Programming
- Take C# Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Buy C# Books
- Buy MCA Books
- Apply for C# Internship
- Apply for Computer Science Internship
- Buy Computer Science Books