Write a C# Sharp program that takes distance and time as input and displays the speed in kilometres per hour and miles per hour

  • برمجة سي شارب
  • برمجة

Write a C# Sharp program that takes distance and time as input and displays the speed in kilometres per hour and miles per hour

Sample Output:

Input distance(metres): 10000                                                                                 
Input timeSec(hour): 1                                                                                        
Input timeSec(minutes): 35                                                                                    
Input timeSec(seconds): 5                                                                                     
Your speed in metres/sec is 1.752848                                                                          
Your speed in km/h is 6.310254                                                                                
Your speed in miles/h is 3.921849

الأجوبة

using System;
public class Exercise7
{
  public static void Main()
  {
    float distance;
    float hour, min, sec;
     
    float timeSec;
    float mps;
    float kph, mph;
     
    Console.Write("Input distance(metres): ");
    distance = Convert.ToSingle(Console.ReadLine());
    Console.Write("Input timeSec(hour): ");
    hour = Convert.ToSingle(Console.ReadLine());
    Console.Write("Input timeSec(minutes): ");
    min = Convert.ToSingle(Console.ReadLine());
    Console.Write("Input timeSec(seconds): ");
    sec = Convert.ToSingle(Console.ReadLine());
     
    timeSec = (hour*3600) + (min*60) + sec;
    mps = distance/timeSec;
    kph = (distance/1000.0f)/(timeSec/3600.0f);
    mph = kph / 1.609f;
     
    Console.WriteLine("Your speed in metres/sec is {0}", mps);
    Console.WriteLine("Your speed in km/h is {0}", kph);
    Console.WriteLine("Your speed in miles/h is {0}", mph);
  }
}
C#
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...