Q:

Write C# Program to enter month number and print number of days in month.

0

Write C# Program to enter month number and print number of days in month.

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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
public class csharpExercise
{
    static void Main(string[] args)
    {
        int month;
 
        Console.WriteLine("Enter month number (1-12): ");
        month = Convert.ToInt32(Console.ReadLine());        
 
        if (month == 1)
        {
            Console.WriteLine("Enter month : January \nNo. of days : 31 days");
        }
        else if (month == 2)
        {
            Console.WriteLine("Enter month : February \nNo. of days : 28 or 29 days");
        }
        else if (month == 3)
        {
            Console.WriteLine("Enter month : March \nNo. of days : 31 days");
        }
        else if (month == 4)
        {
            Console.WriteLine("Enter month : April \nNo. of days : 30 days");
        }
        else if (month == 5)
        {
            Console.WriteLine("Enter month : May \nNo. of days : 31 days");
        }
        else if (month == 6)
        {
            Console.WriteLine("Enter month : June \nNo. of days : 30 days");
        }
        else if (month == 7)
        {
            Console.WriteLine("Enter month : July \nNo. of days : 31 days");
        }
        else if (month == 8)
        {
            Console.WriteLine("Enter month : August \nNo. of days : 31 days");
        }
        else if (month == 9)
        {
            Console.WriteLine("Enter month : September \nNo. of days : 30 days");
        }
        else if (month == 10)
        {
            Console.WriteLine("Enter month : October \nNo. of days : 31 days");
        }
        else if (month == 11)
        {
            Console.WriteLine("Enter month : November \nNo. of days : 30 days");
        }
        else if (month == 12)
        {
            Console.WriteLine("Enter month : December \nNo. of days : 31 days"); ;
        }
        else
        {
            Console.WriteLine("Invalid input! Please enter month number between (1-12).");
        }
        Console.ReadLine();
    }
}

Result:

Enter month number (1-12): 

6

Enter month : June 

No. of days : 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 count total number of notes in... >>
<< Write C# Program to calculate the total marks, per...