Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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:

Enter month number(1-12): 6

30 days

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write C# program to print day of week name using s... >>