# C# Program that takes distance, time to displays speed in km/hr and miles/hr

The Program in C# Program to Compute Difference Between largest and smallest values in Given array is given below:

``````using System;

namespace SpeedCalculator
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello Codeauri Family, enter the distance in kilometers here to find the speed in km/hr and miles/hr:");

Console.WriteLine("Well, enter the time in hours here:");

double speedInKmPerHour = distanceInKm / timeInHours;
double speedInMilesPerHour = distanceInKm / 1.60934 / timeInHours;

Console.WriteLine("Okay, the speed in kilometers per hour is: " + speedInKmPerHour);
Console.WriteLine("Okay, the speed in miles per hour is: " + speedInMilesPerHour);
}
}
}
``````

## Output:

Hello Codeauri Family, enter the distance in kilometers here to find the speed in km/hr and miles/hr:100
Well, enter the time in hours here:5
Okay, the speed in kilometers per hour is: 20
Okay, the speed in miles per hour is: 12.4274547329961

## Pro-Tips💡

Here are the step by step execution of above program:

1. The code starts with the using System; statement, which brings in the System namespace that provides access to various classes and methods, including the Console class used in this code.
2. The code then defines a namespace named SpeedCalculator.
3. Within the namespace, the code defines a class named Program, which contains a Main method.
4. In the Main method, the code first outputs a message to the console asking the user to enter the distance in kilometers.
5. It then reads the input as a string and converts it to a double value using the Convert.ToDouble method.
6. The code then outputs another message asking the user to enter the time in hours.
7. It reads the input again as a string and converts it to a double value.
8. The code calculates the speed in kilometers per hour by dividing the distance in kilometers by the time in hours.
9. It also calculates the speed in miles per hour by dividing the distance in kilometers by 1.60934 (the conversion factor from km to miles) and then by the time in hours.
10. The code outputs the speeds in kilometers per hour and miles per hour to the console.

### Learn C-Sharp ↗

C-sharp covers every topic to learn about C-Sharp thoroughly.

### Learn C Programming ↗

C-Programming covers every topic to learn about C-Sharp thoroughly.

### Learn C++ Programming↗

C++ covers every topic to learn about C-Sharp thoroughly.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

## Programming Languages( Types, Pros and Cons)-Codeauri

What are the types or levels of Programming Languages? The types or levels of programming languages are divided into two types: Types Of Programming Languages: 1.Machine-level Language :1st…

## C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

## C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

## C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

## C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

## C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X