Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _6.Valid_date_or_invalid_date
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Write("day = ");
- int day = Int32.Parse(Console.ReadLine());
- Console.Write("month = ");
- int month = Int32.Parse(Console.ReadLine());
- Console.Write("year = ");
- int year = Int32.Parse(Console.ReadLine());
- int lastDayOfTheMotnth =31 ;
- //if (month == 4 || month == 6 || month == 9 || month == 11)
- //{
- // lastDayOfTheMotnth = 30;
- //}
- //else if (month == 2)
- //{
- // bool isLeapYear = year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
- // lastDayOfTheMotnth = isLeapYear ? 29 : 28;
- //} //работи по-бавно
- switch (month)
- {
- case 4:
- case 6:
- case 9:
- case 11:
- lastDayOfTheMotnth = 30;
- break;
- case 2:
- bool isLeapYear = year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
- lastDayOfTheMotnth = isLeapYear ? 29 : 28;
- break;
- } // switch работи по-бързо
- if (year >= 1 && day >= 1 &&
- month >=1 && month <= 12 &&
- day <= lastDayOfTheMotnth)
- Console.WriteLine("Valid date");
- else
- Console.WriteLine("Invalid date");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment