Q:

Write a program in C# Sharp to read any Month Number in integer and display the number of days for this month

0

Write a program in C# Sharp to read any Month Number in integer and display the number of days for this month

Sample Output:

Read month number and display number of days for that month:                                                  
--------------------------------------------------------------                                        
Input Month No : 2                                                                                            
The 2nd month is a February and have 28 days.                                                                 
in leap year The February month  Have 29 days.

All Answers

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

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
public   class exercise23
   {
       static void Main(string[] args)
     {
   int monno;

           Console.Write("\n\n");
           Console.Write("Read month number and display number of days for that month:\n");
           Console.Write("--------------------------------------------------------------");
           Console.Write("\n\n");

   Console.Write("Input Month No : ");
   monno = Convert.ToInt32(Console.ReadLine());
   switch(monno)
   {
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:
	case 10:
	case 12:
	       Console.Write("Month  have 31 days. \n");
	       break;
	case 2:
	       Console.Write("The 2nd month is a February and have 28 days. \n");
	       Console.Write("in leap year The February month  Have 29 days.\n");
	       break;
	case 4:
	case 6:
	case 9:
	case 11:
	       Console.Write("Month have 30 days. \n");
	       break;
default:
	       Console.Write("invalid Month number.\nPlease try again ....\n");
	       break;
      }
  }
}

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