Q:

Write a program in C# Sharp to get the number of days of a given month for a year

0

Write a program in C# Sharp to get the number of days of a given month for a year.
Test Data:
Input the Month No. : 2
Input the Year : 2017
Expected Output :

The Number of days in the month February is : 28

All Answers

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

using System;
using System.Globalization;

class dttimeex48
{
    static void Main()
    {
	
  	int mn,yr;
  	
    Console.Write("\n\n Find  the number of days of a given month for a year :\n");
	Console.Write("-----------------------------------------------------------\n");	
    Console.Write(" Input the Month No. : ");
    mn = Convert.ToInt32(Console.ReadLine());	
    Console.Write(" Input the Year : ");
    yr = Convert.ToInt32(Console.ReadLine());		
    DateTimeFormatInfo dinfo = new DateTimeFormatInfo();
    string mnum =  dinfo.GetMonthName(mn);   
	int nodays = DateTime.DaysInMonth(yr,mn); 
	Console.WriteLine(" The Number of days in the month {0} is : {1} \n",mnum,nodays);

    }
}

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now