Enter the Speed(km/hr) : 5 Enter the Time(hrs) : 4 Distance Travelled (kms) : 20
Users Online
· Guests Online: 147
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Newest Threads
No Threads created
Hottest Threads
No Threads created
Latest Articles
Articles Hierarchy
C# Program to Calculate Distance, Speed and Time
C# Program to Calculate Distance, Speed and Time
This is a C# Program to calculate the distance travelled by reading speed and time.
Problem Description
This C# Program Calculates the Distance Travelled by Reading Speed and Time.
Problem Solution
Here distance is calculated by multiplying speed and time.
Program/Source Code
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(); } }
Program Explanation
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
Runtime Test Cases
Comments
No Comments have been Posted.
Post Comment
Please Login to Post a Comment.