skipter

C# Data Types - Speed Of Light

Jun 14th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1. using System;
  2. namespace DataBytes___Lab
  3. {
  4.     class Program
  5.     {
  6.         static void Main(string[] args)
  7.         {
  8.             decimal lightYears = decimal.Parse(Console.ReadLine());
  9.  
  10.             decimal lightYearToKm = 9450000000000m;
  11.             decimal speedOfLight = 300000m;
  12.  
  13.             decimal totalKm = lightYears * lightYearToKm;
  14.             decimal totalSeconds = totalKm / speedOfLight;
  15.             decimal weeks = totalSeconds / 604800;
  16.             decimal weeksLeftOver = totalSeconds % 604800;
  17.             decimal days = weeksLeftOver / (60 * 60 * 24);
  18.             decimal daysLeftOver = weeksLeftOver % (60 * 60 * 24);
  19.             decimal hours = daysLeftOver / 3600;
  20.             decimal hoursleftOver = daysLeftOver % 3600;
  21.             decimal minutes = hoursleftOver / 60;
  22.             decimal seconds = hoursleftOver % 60;
  23.  
  24.             Console.WriteLine($"{Math.Floor(weeks)} weeks");
  25.             Console.WriteLine($"{Math.Floor(days)} days");
  26.             Console.WriteLine($"{Math.Floor(hours)} hours");
  27.             Console.WriteLine($"{Math.Floor(minutes)} minutes");
  28.             Console.WriteLine($"{Math.Floor(seconds)} seconds");
  29.            
  30.             // Assume that 1 light year == 9 450 000 000 000 km.
  31.             // Assume that the speed of light == 300 000 km / second.
  32.         }
  33.     }
  34. }
Add Comment
Please, Sign In to add comment