static void Main() { try { Console.Write("Please enter a day number between 1 and 365: "); string line = Console.ReadLine(); int dayNum = int.Parse(line); if (dayNum < 1 || dayNum > 365) { throw new ArgumentOutOfRangeException("Day out of range"); } int monthNum = 0; int[] DaysInMonths = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; foreach (int daysInMonth in DaysInMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); Console.WriteLine("{0} {1}", dayNum, monthName); } catch (Exception caught) { Console.WriteLine("Error: " + caught.Message); } Console.ReadKey(); }
static void Main() { Console.Write("Please enter a day number between 1 and 365: "); string line = Console.ReadLine(); int dayNum = int.Parse(line); int monthNum = 0; foreach (int daysInMonth in DaysInMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); Console.WriteLine("{0} {1}", dayNum, monthName); Console.ReadKey(); }
static void Main(string[] args) { try { Console.Write("Please input a day number between 1 and 365: "); int dayNum = int.Parse(Console.ReadLine()); int monthNum = 0; foreach (int daysInMonth in DaysInMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); Console.WriteLine("{0} {1}", dayNum, monthName); } catch (SystemException caught) { Console.WriteLine("{0}", caught); } }
static void Main(string[] args) { try { int[] DaysInMonths = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; System.Console.Write("Введите день года от 1 до 365: "); string line = Console.ReadLine(); int dayNum = int.Parse(line); if (dayNum < 1 || dayNum > 365) { throw new ArgumentOutOfRangeException("Day out of range"); } int monthNum = 0; foreach (int daysInMonth in DaysInMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); Console.WriteLine("{0} {1}", dayNum, monthName); } catch (Exception caught) { Console.WriteLine(caught); } Console.Read(); }
private static void Main() { int[] DaysInMonths = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; Console.WriteLine("Please enter a day number between 1 and 365: "); int dayNum = int.Parse(Console.ReadLine()); int monthNum = 0; foreach (int daysInMonth in DaysInMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; ++monthNum; } } MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); Console.WriteLine("{0} {1}", dayNum, monthName); Console.ReadLine(); }
static void Main(string[] args) { int[] DaysInMonths = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; System.Console.Write("Введите день года от 1 до 365: "); string line = Console.ReadLine(); int dayNum = int.Parse(line); int monthNum = 0; foreach (int daysInMonth in DaysInMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); Console.WriteLine("{0} {1}", dayNum, monthName); Console.Read(); }
static void forcase() { int monthNum = 0; Console.WriteLine("Please enter the day of the year"); int dayNum = int.Parse(Console.ReadLine()); foreach (int daysInMonth in DaysInMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); Console.WriteLine("{0} {1}", dayNum, monthName); Console.ReadKey(); }
static void Main(string[] args) { Console.Write("Please enter a day number between 1 and 365: "); string line = Console.ReadLine(); int dayNum = int.Parse(line); int monthNum = 0; System.Collections.ICollection DaysInMonths = new int[12] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; foreach (int daysInMonth in DaysInMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); Console.WriteLine("{0} {1}", dayNum, monthName); Console.ReadLine(); }
static void Main(string[] args) { Console.Write("Please enter the number of the day between 1 and 365: "); string line = Console.ReadLine(); int daynum = int.Parse(line); int monthnum = 0; foreach (int daysInMonth in DaysInMonths) { if (daynum <= daysInMonth) { break; } else { daynum -= daysInMonth; monthnum++; } } // end: MonthName temp = (MonthName)monthnum; string monthname = temp.ToString(); //switch (monthnum) //{ // case 0: // monthname = "january"; break; // case 1: // monthname = "february"; break; // case 2: // monthname = "march"; break; // case 3: // monthname = "april"; break; // case 4: // monthname = "may"; break; // case 5: // monthname = "june"; break; // case 6: // monthname = "july"; break; // case 7: // monthname = "august"; break; // case 8: // monthname = "september"; break; // case 9: // monthname = "october"; break; // case 10: // monthname = "november"; break; // case 11: // monthname = "december"; break; // default: // monthname = "not done yet"; break; //} Console.WriteLine("{0} {1}", daynum, monthname); }
static void Main() { try { Console.Write("Please enter the year: "); string line = Console.ReadLine(); int yearNum = int.Parse(line); bool isLeapYear = (yearNum % 4 == 0) && (yearNum % 100 != 0 || yearNum % 400 == 0); if (isLeapYear) { Console.WriteLine(" IS a leap year"); } else { Console.WriteLine(" Is NOT a leap year"); } int maxDayNum = isLeapYear ? 366 : 365; Console.Write("Please enter a day number between 1 and {0}: ", maxDayNum); line = Console.ReadLine(); int dayNum = int.Parse(line); if (dayNum < 1 || dayNum > maxDayNum) { throw new ArgumentOutOfRangeException("Day out of range"); } int monthNum = 0; int[] DaysInMonths = new int[] { 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; if (isLeapYear) { DaysInMonths[1] = 29; } else { DaysInMonths[1] = 28; } foreach (int daysInMonth in DaysInMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); Console.WriteLine("{0} {1}", dayNum, monthName); } catch (Exception caught) { Console.WriteLine("Error: {0}", caught.Message); } Console.ReadKey(); }
static void Main() { try { Console.WriteLine("Введите год: "); string line = Console.ReadLine(); // ввод номера дня года int yearNum = int.Parse(line); Console.WriteLine("Введите номер дня от 1 до 365: "); line = Console.ReadLine(); // ввод номера дня года int dayNum = int.Parse(line); // приведение к целочисленому значению bool isLeapYear = (yearNum % 4 == 0) && (yearNum % 100 != 0) || (yearNum % 400 == 0); //if (isLeapYear == true) //{ // Console.WriteLine("Год является високосным."); //} //else //{ // Console.WriteLine("Год не является високосным."); //} if (dayNum < 1 || dayNum > 365) { throw new ArgumentOutOfRangeException("Число не соответствует номеру дня"); } int monthNum = 0; foreach (int daysInMonth in DaysInMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); Console.WriteLine("{0}, {1}", dayNum, monthName); Console.ReadLine(); } catch (Exception caught) { Console.WriteLine(caught); } }
static void Main(string[] args) { try { System.Console.Write("Введите год: "); string line = Console.ReadLine(); int yearNum = int.Parse(line); bool isLeapYear = (yearNum % 4 == 0) && (yearNum % 100 != 0 || yearNum % 400 == 0); int maxDayNum = isLeapYear ? 366 : 365; if (isLeapYear) { Console.WriteLine(" год високосный"); } else { Console.WriteLine(" год не високосный"); } int[] DaysInMonths = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; System.Console.Write("Введите день года от 1 до {0}: ", maxDayNum); string day = Console.ReadLine(); int dayNum = int.Parse(day); if (dayNum < 1 || dayNum > maxDayNum) { throw new ArgumentOutOfRangeException("Day out of range"); } int monthNum = 0; foreach (int daysInMonth in DaysInMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); Console.WriteLine("{0} {1}", dayNum, monthName); } catch (Exception caught) { Console.WriteLine(caught); } Console.Read(); }
static void Main(string[] args) { try { const int minDayNum = 1; const int maxDayNum = 365; Console.Write("Please input a day number between 1 and 365: "); int dayNum = int.Parse(Console.ReadLine()); if (dayNum < minDayNum || dayNum > maxDayNum) { throw new ArgumentOutOfRangeException("Day out of range"); } int monthNum = 0; foreach (int daysInMonth in DaysInMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); Console.WriteLine("{0} {1}", dayNum, monthName); } catch (Exception caught) { Console.WriteLine("An exception encountered: {0}", caught); } }
static void Main(string[] args) { try { Console.Write("Please input a day number between 1 and 365: "); string line = Console.ReadLine(); int dayNum = int.Parse(line); if ((dayNum < 1) || (dayNum > 365)) { throw new ArgumentOutOfRangeException("Day out of range"); } int monthNum = 0; foreach (int daysInMonth in DaysInMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); Console.WriteLine("{0} {1}", dayNum, monthName); Console.ReadKey(); //Для удобства проверки } catch (SystemException caught) { Console.WriteLine(caught); Console.ReadKey(); //Для удобства проверки } }
private static void Main() { try { int[] DaysInMonths = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; Console.WriteLine("Please enter a day number between 1 and 365: "); int dayNum = int.Parse(Console.ReadLine()); if (dayNum < 1 || dayNum > 365) { throw new ArgumentOutOfRangeException("Day out of range"); } int monthNum = 0; foreach (int daysInMonth in DaysInMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; ++monthNum; } } MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); Console.WriteLine("{0} {1}", dayNum, monthName); } catch (Exception ex) { Console.WriteLine(ex); } Console.ReadLine(); }
public static void forcase() { try { int monthNum = 0; Console.WriteLine("Please enter the day of the year"); int dayNum = int.Parse(Console.ReadLine()); if (dayNum < 1 || dayNum > 365) { throw new ArgumentOutOfRangeException("Day out of range"); } foreach (int daysInMonth in DaysInMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); Console.WriteLine("{0} {1}", dayNum, monthName); Console.ReadKey(); } catch (Exception caught) { Console.WriteLine(caught); Console.ReadKey(); } }
static void Main(string[] args) { try { Console.Write("Please enter the year:"); int yearNum = int.Parse(Console.ReadLine()); bool isLeapYear = (yearNum % 4 == 0) && (yearNum % 100 != 0 || yearNum % 400 == 0); const int minDayNum = 1; int maxDayNum = isLeapYear ? 366 : 365; Console.Write("Please input a day number between 1 and {0}: ", maxDayNum); int dayNum = int.Parse(Console.ReadLine()); if (dayNum < minDayNum || dayNum > maxDayNum) { throw new ArgumentOutOfRangeException("Day out of Range"); } int monthNum = 0; if (isLeapYear) { foreach (int daysInMonth in DaysInLeapMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } } else { foreach (int daysInMonth in DaysInMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } } MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); Console.WriteLine("{0} {1}", dayNum, monthName); } catch (Exception caught) { Console.WriteLine(caught); } }
static void Main(string[] args) { try { Console.Write("Please enter the year: "); string line = Console.ReadLine(); int yearNum = int.Parse(line); bool isLeapYear = (yearNum % 4 == 0 && ((yearNum % 100 != 0) || (yearNum % 400 == 0))); int maxDayNum; if (isLeapYear) { maxDayNum = 366; } else { maxDayNum = 365; } // if (isLeapYear) // { // isLeapYear = true; // Console.WriteLine("{0} is a Leap year", yearNum); // } // else // { // isLeapYear = false; // Console.WriteLine("{0} is NOT a Leap year", yearNum); // } Console.Write("Please input a day number between 1 and {0}: ", maxDayNum); int dayNum = int.Parse(Console.ReadLine()); if (dayNum < 1 || dayNum > maxDayNum) { throw new ArgumentOutOfRangeException("Day out of Range"); } int monthNum = 0; if (isLeapYear) { foreach (int daysInMonth in DaysInLeapMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } } else { foreach (int daysInMonth in DaysInMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } } MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); Console.WriteLine("{0} {1}", dayNum, monthName); } catch (Exception caught) { Console.WriteLine(caught); } }
static void Main(string[] args) { try { Console.Write("Please enter the year: "); string line = Console.ReadLine(); int yearNum = int.Parse(line); bool isLeapYear = (yearNum % 4 == 0) && (yearNum % 100 != 0 || yearNum % 400 == 0); int maxDayNum = isLeapYear ? 366 : 365; Console.Write("Please enter a day number between 1 and {0}: ", maxDayNum); line = Console.ReadLine(); int dayNum = int.Parse(line); int monthNum = 0; if (dayNum < 1 || dayNum > maxDayNum) { throw new ArgumentOutOfRangeException("Day out of range"); } System.Collections.ICollection DaysInMonths = new int[12] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; System.Collections.ICollection DaysInMonthsLeap = new int[12] { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; if (isLeapYear) { foreach (int daysInMonth in DaysInMonthsLeap) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } } else { foreach (int daysInMonth in DaysInMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } } MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); Console.WriteLine("{0} {1}", dayNum, monthName); Console.ReadLine(); } catch (Exception caught) { Console.WriteLine(caught); } Console.ReadLine(); }
static void Main() { try { Console.WriteLine("Please enter the Year"); string line = Console.ReadLine(); int yearNum = int.Parse(line); bool isLeapYear; int maxDayNum; if (yearNum % 4 == 0) { isLeapYear = true; maxDayNum = 366; } else { isLeapYear = false; maxDayNum = 365; } Console.WriteLine("Please enter a day number between 1 and {0}", maxDayNum); line = Console.ReadLine(); int dayNum = int.Parse(line); if (dayNum < 1 || dayNum > maxDayNum) { throw new ArgumentOutOfRangeException("Day out of range"); } int monthNum = 0; if (isLeapYear == true) { foreach (int daysInMonth in DaysInLeapMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } } else { foreach (int daysInMonth in DaysInMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } } /*if (dayNum <= 31) { // January * goto End; * } else { * dayNum -= 31; * monthNum++; * } * * if (dayNum <= 28) { // February * goto End; * } else { * dayNum -= 28; * monthNum++; * } * * if (dayNum <= 31) { // March * goto End; * } else { * dayNum -= 31; * monthNum++; * } * * if (dayNum <= 30) { // April * goto End; * } else { * dayNum -= 30; * monthNum++; * } * * if (dayNum <= 31) { // May * goto End; * } else { * dayNum -= 31; * monthNum++; * } * * * if (dayNum <= 30) { // June * goto End; * } else { * dayNum -= 30; * monthNum++; * } * * if (dayNum <= 31) { // July * goto End; * } else { * dayNum -= 31; * monthNum++; * } * * if (dayNum <= 31) { // August * goto End; * } else { * dayNum -= 31; * monthNum++; * } * * if (dayNum <= 30) { // September * goto End; * } else { * dayNum -= 30; * monthNum++; * } * * if (dayNum <= 31) { // October * goto End; * } else { * dayNum -= 31; * monthNum++; * } * if (dayNum <= 31) { // ноябрь * goto End; * } else { * dayNum -= 30; * monthNum++; * } * if (dayNum <= 31) { // декабрь * goto End; * } else { * dayNum -= 31; * monthNum++; * }*/ //End: //string MonthName; // MonthName temp = (MonthName)monthNum; //string monthName = temp.ToString(); MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); switch (monthNum) { case 0: monthName = "January"; break; case 1: monthName = "February"; break; case 2: monthName = "March"; break; case 3: monthName = "April"; break; case 4: monthName = "May"; break; case 5: monthName = "June"; break; case 6: monthName = "July"; break; case 7: monthName = "August"; break; case 8: monthName = "September"; break; case 9: monthName = "October"; break; case 10: monthName = "November"; break; case 11: monthName = "December"; break; default: monthName = "not done yet"; break; } Console.WriteLine("{0},{1}", dayNum, monthName); Console.ReadKey(); } catch (ArgumentOutOfRangeException) { Console.WriteLine("Day out of range"); Console.ReadKey(); } }
static void Main(string[] args) { try { Console.Write("Please enter the year: "); int yearNum = int.Parse(Console.ReadLine()); bool isLeapYear = (yearNum % 4 == 0) && ((yearNum % 100 != 0) || (yearNum % 100 == 0)); int maxDayNum = isLeapYear ? 365 : 366; if (isLeapYear) { Console.WriteLine("Is a leap year"); } else { Console.WriteLine("Is NOT a leap year"); } Console.Write("Please enter a day number between 1 and 365: "); int dayNum = int.Parse(Console.ReadLine()); if ((dayNum < 1) || (dayNum > maxDayNum)) { throw new ArgumentOutOfRangeException("Day out of range"); } int monthNum = 0; var DaysInMonths = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; var DaysInLeapMonths = new int[] { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; if (isLeapYear) { foreach (int daysInMonth in DaysInLeapMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } } else { foreach (int daysInMonth in DaysInMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } } MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); Console.WriteLine("{0} {1} {2}", dayNum, monthName, yearNum); } catch (Exception caught) { Console.WriteLine(caught); } Console.ReadKey(); }
static void Main(string[] args) { Console.Write("Please enter a day number between 1 and 365: "); string line = Console.ReadLine(); int dayNum = int.Parse(line); int monthNum = 0; if (dayNum <= 31) { goto End; } else { dayNum -= 31; monthNum++; } if (dayNum <= 28) { goto End; } else { dayNum -= 28; monthNum++; } if (dayNum <= 31) { goto End; } else { dayNum -= 31; monthNum++; } if (dayNum <= 30) { goto End; } else { dayNum -= 30; monthNum++; } if (dayNum <= 31) { goto End; } else { dayNum -= 31; monthNum++; } if (dayNum <= 30) { goto End; } else { dayNum -= 30; monthNum++; } if (dayNum <= 31) { goto End; } else { dayNum -= 31; monthNum++; } if (dayNum <= 31) { goto End; } else { dayNum -= 31; monthNum++; } if (dayNum <= 30) { goto End; } else { dayNum -= 30; monthNum++; } if (dayNum <= 31) { goto End; } else { dayNum -= 31; monthNum++; } if (dayNum <= 30) { goto End; } else { dayNum -= 30; monthNum++; } if (dayNum <= 31) { goto End; } else { dayNum -= 31; monthNum++; } End: MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); Console.WriteLine("{0} {1}", dayNum, monthName); Console.ReadLine(); }
public static void forcase() { try { int monthNum = 0; //year Console.WriteLine("Please enter the year:"); int yearNum = int.Parse(Console.ReadLine()); Boolean isLeapYear = (yearNum % 4 == 0) && (yearNum % 100 != 0 || yearNum % 400 == 0); int maxDayNum = isLeapYear ? 366 : 365; //day Console.WriteLine("Please enter the day of the year:"); int dayNum = int.Parse(Console.ReadLine()); if (dayNum < 1 || dayNum > maxDayNum) { throw new ArgumentOutOfRangeException("Day out of range"); } if (isLeapYear) { foreach (int daysInMonth in DaysInLeapMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } } else { foreach (int daysInMonth in DaysInMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } } MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); Console.WriteLine("{0} {1}", dayNum, monthName); Console.ReadKey(); } catch (Exception caught) { Console.WriteLine(caught); Console.ReadKey(); } }
//static int Day; #region old code /* if (Day<= 31) * monthName = "Januaru"; * else if (Day >= 31&&Day <= 59) * monthName = "February"; * else if(Day >= 59 && Day <= 90) * monthName = "Marth"; * else if (Day >= 90 && Day <= 121) * monthName = "Aptil"; * else if (Day >= 121 && Day <= 151) * monthName = "May"; * else if (Day >= 151 && Day <= 182) * monthName = "June"; * else if (Day >= 182 && Day <= 212) * monthName = "July"; * else if (Day >= 212 && Day <= 243) * monthName = "August"; * else if (Day >= 243 && Day <= 273) * monthName = "Stptember"; * else if (Day >= 273 && Day <= 304) * monthName = "October"; * else if (Day >= 304 && Day <= 334) * monthName = "November"; * else if (Day >= 334 && Day <= 365) * monthName = "December"; * * else * { * monthName = "Такого месяца не существует"; * } * return monthName;*/ #endregion static void Main(string[] args) { try { Console.Write("Please enter the year: "); string line = Console.ReadLine(); int yearNum = int.Parse(line); bool isLeapYear = (yearNum % 4 == 0); if (isLeapYear) { Console.WriteLine(" IS a leap year"); } else { Console.WriteLine(" is NOT a leap year"); } int maxDayNum = isLeapYear ? 366 : 365; ArrayList DaysInMonths = new ArrayList() { 31, 28, 31, 30, 31, 31, 31, 30, 31, 30, 30, 31 }; ArrayList DaysInMonthsLeap = new ArrayList() { 31, 29, 31, 30, 31, 31, 31, 30, 31, 30, 30, 31 }; Console.WriteLine("Введите день от 1 до 365 или 366 если год високосный"); string day = Console.ReadLine(); int Day = int.Parse(day); if (Day < 1 || Day > maxDayNum) { throw new ArgumentOutOfRangeException("Day out of range"); } int MonthNam = 0; if (isLeapYear) { foreach (int daysInMonth in DaysInMonthsLeap) { if (Day <= daysInMonth) { break; } else { Day -= daysInMonth; MonthNam++; } } } else { foreach (int daysInMonth in DaysInMonths) { if (Day <= daysInMonth) { break; } else { Day -= daysInMonth; MonthNam++; } } } MonthName temp = (MonthName)MonthNam; string MonthName = temp.ToString(); Console.WriteLine("{0} {1}", Day, MonthName); } catch (Exception caught) { Console.WriteLine(caught); } Console.ReadKey(); }
static void Main(string[] args) { System.Console.Write("Please enter a day number between 1 and 365:"); string line = Console.ReadLine(); int dayNum = int.Parse(line); int monthNum = 0; var DaysInMonths = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; foreach (int daysInMonth in DaysInMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } // if (dayNum <= 31) // { // January // goto End; // } // else // { // dayNum -= 31; // monthNum++; // } // if (dayNum <= 28) // { // February // goto End; // } // else // { // dayNum -= 28; // monthNum++; // } // if (dayNum <= 31) // { // March // goto End; // } // else // { // dayNum -= 31; // monthNum++; // } // if (dayNum <= 30) // { // April // goto End; // } // else // { // dayNum -= 30; // monthNum++; // } // if (dayNum <= 31) // { // May // goto End; // } // else // { // dayNum -= 31; // monthNum++; // } // if (dayNum <= 30) // { // June // goto End; // } // else // { // dayNum -= 30; // monthNum++; // } // if (dayNum <= 31) // { // July // goto End; // } // else // { // dayNum -= 31; // monthNum++; // } // if (dayNum <= 31) // { // August // goto End; // } // else // { // dayNum -= 31; // monthNum++; // } // if (dayNum <= 30) // { // September // goto End; // } // else // { // dayNum -= 30; // monthNum++; // } // if (dayNum <= 31) // { // October // goto End; // } // else // { // dayNum -= 31; // monthNum++; // } // if (dayNum <= 30) // { // November // goto End; // } // else // { // dayNum -= 30; // monthNum++; // } // if (dayNum <= 31) // { // December // goto End; // } // else // { // dayNum -= 31; // monthNum++; // } //End: MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); // string monthName; //switch (monthNum) //{ // case 0: // monthName = "January"; break; // case 1: // monthName = "February"; break; // case 2: // monthName = "March"; break; // case 3: // monthName = "April"; break; // case 4: // monthName = "May"; break; // case 5: // monthName = "June"; break; // case 6: // monthName = "July"; break; // case 7: // monthName = "August"; break; // case 8: // monthName = "September"; break; // case 9: // monthName = "October"; break; // case 10: // monthName = "November"; break; // case 11: // monthName = "December"; break; // default: // monthName = "not done yet"; break; //} Console.WriteLine("{0} {1}", dayNum, monthName); Console.ReadKey(); }
private static void Main() { try { int[] DaysInMonths = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int[] DaysInLeapMonths = new int[] { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; Console.WriteLine("Please enter the year: "); int yearNum = int.Parse(Console.ReadLine()); bool isLeapYear = yearNum % 4 == 0 && yearNum % 100 != 0 || yearNum % 400 == 0; int maxDayNum = isLeapYear ? 366 : 365; Console.WriteLine("Please enter a day number between 1 and {0}: ", maxDayNum); int dayNum = int.Parse(Console.ReadLine()); if (dayNum < 1 || dayNum > maxDayNum) { throw new ArgumentOutOfRangeException("Day out of range"); } int monthNum = 0; if (isLeapYear) { foreach (int daysInMonth in DaysInLeapMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; ++monthNum; } } } else { foreach (int daysInMonth in DaysInMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; ++monthNum; } } } MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); Console.WriteLine("{0} {1}", dayNum, monthName); } catch (Exception ex) { Console.WriteLine(ex); } Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("Please enter a day number between 1 and 365: "); string line = Console.ReadLine(); int dayNum = int.Parse(line); int monthNum = 0; if (dayNum <= 31) // January { goto End; } else { dayNum -= 31; monthNum++; } if (dayNum <= 28) // February { goto End; } else { dayNum -= 28; monthNum++; } if (dayNum <= 31) // March { goto End; } else { dayNum -= 31; monthNum++; } if (dayNum <= 30) // April { goto End; } else { dayNum -= 30; monthNum++; } if (dayNum <= 31) // May { goto End; } else { dayNum -= 31; monthNum++; } if (dayNum <= 30) // June { goto End; } else { dayNum -= 30; monthNum++; } if (dayNum <= 31) // July { goto End; } else { dayNum -= 31; monthNum++; } if (dayNum <= 31) // August { goto End; } else { dayNum -= 31; monthNum++; } if (dayNum <= 30) // September { goto End; } else { dayNum -= 30; monthNum++; } if (dayNum <= 31) // October { goto End; } else { dayNum -= 31; monthNum++; } if (dayNum <= 30) // November { goto End; } else { dayNum -= 30; monthNum++; } if (dayNum <= 31) // December { goto End; } else { dayNum -= 31; monthNum++; } End: MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); //string monthName; //switch (monthnum) //{ // case 0: // monthname = "january"; break; // case 1: // monthname = "february"; break; // case 2: // monthname = "march"; break; // case 3: // monthname = "april"; break; // case 4: // monthname = "may"; break; // case 5: // monthname = "june"; break; // case 6: // monthname = "july"; break; // case 7: // monthname = "august"; break; // case 8: // monthname = "september"; break; // case 9: // monthname = "october"; break; // case 10: // monthname = "november"; break; // case 11: // monthname = "december"; break; // default: // monthname = "not done yet"; break; //} Console.WriteLine("{0} {1}", dayNum, monthName); Console.ReadKey(); }
static void Main(string[] args) { try { Console.Write("Введите год "); int num_year = Convert.ToInt32(Console.ReadLine()); bool what_year = (num_year % 4 == 0) && (num_year % 100 != 0 || num_year % 400 == 0); //if (what_year) //{ Console.WriteLine("Введенный год - високосный"); } //else //{ Console.WriteLine("Введенный год - не високосный"); } int max_num_day = what_year ? 366 : 365; Console.Write("Введите номер дня в году от 1 до {0} ", max_num_day); int num_day = Convert.ToInt32(Console.ReadLine()); if (num_day < 1 || num_day > max_num_day) { throw new ArgumentOutOfRangeException("Вы ввели недопустимый день года"); } int num_month = 0; if (num_day <= 31) { goto End; } //Январь else { num_day -= 31; num_month++; } if (what_year) { if (num_day <= 29) { goto End; } //Февраль else { num_day -= 29; num_month++; } } else { if (num_day <= 28) { goto End; } //Февраль else { num_day -= 28; num_month++; } } if (num_day <= 31) { goto End; } //Март else { num_day -= 31; num_month++; } if (num_day <= 30) { goto End; } //Апрель else { num_day -= 30; num_month++; } if (num_day <= 31) { goto End; } //Май else { num_day -= 31; num_month++; } if (num_day <= 30) { goto End; } //Июнь else { num_day -= 30; num_month++; } if (num_day <= 31) { goto End; } //Июль else { num_day -= 31; num_month++; } if (num_day <= 31) { goto End; } //Август else { num_day -= 31; num_month++; } if (num_day <= 30) { goto End; } //Сентябрь else { num_day -= 30; num_month++; } if (num_day <= 31) { goto End; } //Октябрь else { num_day -= 31; num_month++; } if (num_day <= 30) { goto End; } //Ноябрь else { num_day -= 30; num_month++; } if (num_day <= 31) { goto End; } //Декабрь else { num_day -= 31; num_month++; } End: MonthName temp = (MonthName)num_month; string name_month = temp.ToString(); Console.WriteLine("{0} {1}", num_day, name_month); } catch (Exception caught) { Console.WriteLine(caught); } }
static void Main(string[] args) { Console.Write("Please enter a day number between 1 and 365: "); string line = Console.ReadLine(); int dayNum = int.Parse(line); int monthNum = 0; // if (dayNum <= 31) // { // January // goto End; // } // else // { // dayNum -= 31; // monthNum++; // } // if (dayNum <= 28) // { // February // goto End; // } // else // { // dayNum -= 28; // monthNum++; // } // if (dayNum <= 31) // { // March // goto End; // } // else // { // dayNum -= 31; // monthNum++; // } // if (dayNum <= 30) // { // April // goto End; // } // else // { // dayNum -= 30; // monthNum++; // } // if (dayNum <= 31) // { // May // goto End; // } // else // { // dayNum -= 31; // monthNum++; // } // if (dayNum <= 30) // { // June // goto End; // } // else // { // dayNum -= 30; // monthNum++; // } // if (dayNum <= 31) // { // July // goto End; // } // else // { // dayNum -= 31; // monthNum++; // } // if (dayNum <= 31) // { // August // goto End; // } // else // { // dayNum -= 31; // monthNum++; // } // if (dayNum <= 30) // { // September // goto End; // } // else // { // dayNum -= 30; // monthNum++; // } // if (dayNum <= 31) // { // October // goto End; // } // else // { // dayNum -= 31; // monthNum++; // } // if (dayNum <= 30) // { // November // goto End; // } // else // { // dayNum -= 30; // monthNum++; // } // if (dayNum <= 31) // { // December // goto End; // } // else // { // dayNum -= 31; // monthNum++; // } //End: //string monthName; //switch (monthNum) //{ // case 0: // monthName = "January"; break; // case 1: // monthName = "February"; break; // case 2: // monthName = "March"; break; // case 3: // monthName = "April"; break; // case 4: // monthName = "May"; break; // case 5: // monthName = "June"; break; // case 6: // monthName = "July"; break; // case 7: // monthName = "August"; break; // case 8: // monthName = "September"; break; // case 9: // monthName = "October"; break; // case 10: // monthName = "November"; break; // case 11: // monthName = "December"; break; // default: // monthName = "not done yet"; break; //} MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); Console.WriteLine("{0} {1}", dayNum, monthName); Console.ReadKey(); //Для удобства проверки вывода }
static void Main(string[] args) { Console.WriteLine("Please, enter the year"); string line = Console.ReadLine(); int yearNum = int.Parse(line); bool isLeapYear = false; int maxDayNum = 365; if (yearNum % 4 == 0) { isLeapYear = true; maxDayNum++; } Console.WriteLine("Please, enter the day number between 1 and {0}: ", maxDayNum); line = Console.ReadLine(); try { int dayNum = int.Parse(line); // dayNum = sum of all days of the months before + now data if (dayNum > 365 || dayNum < 1) { throw new ArgumentOutOfRangeException("Day out of Range"); } int monthNum = 0; if (isLeapYear) { foreach (int daysInLeapMonth in DaysInLeapMonths) { if (dayNum <= daysInLeapMonth) { break; } else { dayNum -= daysInLeapMonth; monthNum++; } } } else { foreach (int daysInMonth in DaysInMonths) { if (dayNum <= daysInMonth) { break; } else { dayNum -= daysInMonth; monthNum++; } } } //if (dayNum <= 31) // January // goto End; //else //{ // dayNum -= 31; // monthNum++; //} //if (dayNum <= 28 || (dayNum <= 29 && isLeapYear)) // February // goto End; //else //{ // dayNum -= 28; //if (isLeapYear) // dayNum--; // monthNum++; //} //if (dayNum <= 31) // March // goto End; //else //{ // dayNum -= 31; // monthNum++; //} //if (dayNum <= 30) // April // goto End; //else //{ // dayNum -= 30; // monthNum++; //} //if (dayNum <= 31) // May // goto End; //else //{ // dayNum -= 31; // monthNum++; //} //if (dayNum <= 30) // June // goto End; //else //{ // dayNum -= 30; // monthNum++; //} //if (dayNum <= 31) // July // goto End; //else //{ // dayNum -= 31; // monthNum++; //} //if (dayNum <= 31) // August // goto End; //else //{ // dayNum -= 31; // monthNum++; //} //if (dayNum <= 30) // September // goto End; //else //{ // dayNum -= 30; // monthNum++; //} //if (dayNum <= 31) // October // goto End; //else //{ // dayNum -= 31; // monthNum++; //} //if (dayNum <= 31) // November // goto End; //else //{ // dayNum -= 30; // monthNum++; //} //if (dayNum <= 31) // December // goto End; //else //{ // dayNum -= 31; // monthNum++; //} //End: //MonthName temp = (MonthName)monthNum; //string monthName = temp.ToString(); //string monthName; //switch (monthNum) //{ // case 0: // monthName = "January"; break; // case 1: // monthName = "February"; break; // case 2: // monthName = "March"; break; // case 3: // monthName = "April"; break; // case 4: // monthName = "May"; break; // case 5: // monthName = "June"; break; // case 6: // monthName = "July"; break; // case 7: // monthName = "August"; break; // case 8: // monthName = "September"; break; // case 9: // monthName = "October"; break; // case 10: // monthName = "November"; break; // case 11: // monthName = "December"; break; // default: // monthName = "not done yet"; break; //} MonthName temp = (MonthName)monthNum; string monthName = temp.ToString(); Console.WriteLine("{0} {1}", monthName, dayNum); } catch (ArgumentOutOfRangeException wrong_data) { Console.WriteLine("Error: {0} \nStack: {1}", wrong_data.Message, wrong_data.StackTrace); } }