Check Total Days in Month and The Year Is Leap or Not in c# using Switch-Case.

 

CODE:


 Console.WriteLine("Enter Year:");

            int year = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Enter Month Which Do You Want To Check:");

            int month = Convert.ToInt32(Console.ReadLine());

            switch (month)

            {

                case 1:

                    Console.WriteLine("The Month is January Total days in this month is 31");

                    break;

                case 2:

                    if ((year%4==0 && year%100 !=0)||year%400==0)

                    {

                        Console.WriteLine("{0} Year is leap",year);

                        Console.WriteLine("days in this month is 29");

                    }

                    else

                    {

                        Console.WriteLine("{0} Year is not leap", year);

                        Console.WriteLine("days in this month is 28");

                    }

                    break;

                case 3:

                    Console.WriteLine("The Month is March Total days in this month is 31");

                    break;

                case 4:

                    Console.WriteLine("The Month is April Total days in this month is 30");

                    break;

                case 5:

                    Console.WriteLine("The Month is May Total days in this month is 31");

                    break;

                case 6:

                    Console.WriteLine("The Month is June Total days in this month is 30");

                    break;

                case 7:

                    Console.WriteLine("The Month is July Total days in this month is 31");

                    break;

                case 8:

                    Console.WriteLine("The Month is August Total days in this month is 31");

                    break;

                case 9:

                    Console.WriteLine("The Month is September Total days in this month is 30");

                    break;

                case 10:

                    Console.WriteLine("The Month is October Total days in this month is 31");

                    break;

                case 11:

                    Console.WriteLine("The Month is November Total days in this month is 30");

                    break;

                case 12:

                    Console.WriteLine("The Month is December Total days in this month is 31");

                    break;

                default:

                    Console.WriteLine("Invalid Month");

                    break;

            }


        }

    }

}

Comments

Popular posts from this blog

Vertical and Reverse Paramid in c# using loop.

Calculator in c# using Static Methods

Calculator in c# using Method void method