Write C# program to print number of days in a month using switch case

Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..

using System;
 
public class csharpExercise
{
    static void Main(string[] args)
    {
 
     int monthnumber;
 
    //Reading a month number from user
 
    Console.WriteLine("Enter month number(1-12): ");
    monthnumber = Convert.ToInt32(Console.ReadLine());
 
    switch (monthnumber)
    {
        case 1: Console.WriteLine("31 days");
            break;
        case 2: Console.WriteLine("28 or 29 days");
            break;
        case 3: Console.WriteLine("31 days");
            break;
        case 4: Console.WriteLine("30 days");
            break;
        case 5: Console.WriteLine("31 days");
            break;
        case 6: Console.WriteLine("30 days");
            break;
        case 7: Console.WriteLine("31 days");
            break;
        case 8: Console.WriteLine("31 days");
            break;
        case 9: Console.WriteLine("30 days");
            break;
        case 10: Console.WriteLine("31 days");
            break;
        case 11: Console.WriteLine("30 days");
            break;
        case 12: Console.WriteLine("31 days");
            break;
        default:
            Console.WriteLine("Invalid input!!! enter month number between 1-12");
            break;
 
 
      }
    Console.ReadLine();
 
    }
}

Result

Write C# program to print number of days in a month using switch case
Write C# program to print number of days in a month using switch case

Leave a Comment

x