Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Tester
- {
- class Program
- {
- static void Main(string[] args)
- {
- //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.
- Console.WriteLine("The following are results of the 4 sections of equations"); //An outut to help show whats on the console.
- string[] DaysOfTheWeek = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; //Array used as output for days of week
- int Day = DateTime.Now.Day; //Sets int day as todays date
- Console.WriteLine($"Day = {Day}"); //Writes this out to concole This is only done to help see the formula work
- int Month = ((DateTime.Now.Month + 9) % 12) + 1;
- Console.WriteLine($"Month = {Month}");//Writes this out to concole This is only done to help see the formula work
- int YearsInCentury = Month > 10 ? //See http://mathforum.org/dr.math/faq/faq.calendar.html on why this is 10.
- (DateTime.Now.Year - 1) % 100 :
- DateTime.Now.Year % 100;
- Console.WriteLine($"Years in Century = {YearsInCentury}");//Writes this out to concole This is only done to help see the formula work
- int Century = YearsInCentury == 99 && Month > 10 ?
- (DateTime.Now.Year - 100) / 100 :
- DateTime.Now.Year / 100;
- Console.WriteLine($"Century = {Century}");//Writes this out to concole This is only done to help see the formula work
- int DayOfWeek = ((((int)((2.6 * (float)Month) - 0.2)
- + Day + YearsInCentury + (YearsInCentury / 4)
- + (Century / 4) - (2 * Century))) % 7);
- Console.WriteLine($"\nThe day of the week is: {DaysOfTheWeek[DayOfWeek]}");
- Console.Read();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement