Advertisement
Guest User

Group41

a guest
Oct 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Tester
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. //This program will derive the day of the week for todays date (DateTime.Now.Day) and output this as Mon-Sun as per the array below.
  10.  
  11. Console.WriteLine("The following are results of the 4 sections of equations"); //An outut to help show whats on the console.
  12.  
  13. string[] DaysOfTheWeek = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; //Array used as output for days of week
  14.  
  15. int Day = DateTime.Now.Day; //Sets int day as todays date
  16. Console.WriteLine($"Day = {Day}"); //Writes this out to concole This is only done to help see the formula work
  17.  
  18. int Month = ((DateTime.Now.Month + 9) % 12) + 1;
  19. Console.WriteLine($"Month = {Month}");//Writes this out to concole This is only done to help see the formula work
  20.  
  21. int YearsInCentury = Month > 10 ? //See http://mathforum.org/dr.math/faq/faq.calendar.html on why this is 10.
  22. (DateTime.Now.Year - 1) % 100 :
  23. DateTime.Now.Year % 100;
  24. Console.WriteLine($"Years in Century = {YearsInCentury}");//Writes this out to concole This is only done to help see the formula work
  25.  
  26. int Century = YearsInCentury == 99 && Month > 10 ?
  27. (DateTime.Now.Year - 100) / 100 :
  28. DateTime.Now.Year / 100;
  29. Console.WriteLine($"Century = {Century}");//Writes this out to concole This is only done to help see the formula work
  30.  
  31. int DayOfWeek = ((((int)((2.6 * (float)Month) - 0.2)
  32. + Day + YearsInCentury + (YearsInCentury / 4)
  33. + (Century / 4) - (2 * Century))) % 7);
  34.  
  35. Console.WriteLine($"\nThe day of the week is: {DaysOfTheWeek[DayOfWeek]}");
  36. Console.Read();
  37.  
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement