Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Exercises: Read month number and display number of days for that month


C# Sharp Conditional Statement: Exercise-23 with Solution

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

Sample Solution:-

C# Sharp Code:

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;
      }
  }
}

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.

Pictorial Presentation:

Conditional Statement: Read month number and display number of days for that month.

Flowchart:

Flowchart: Read month number and display number of days for that month.

C# Sharp Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a program in C# Sharp to read any Month Number in integer and display Month name in the word.
Next: Write a program in C# Sharp which is a Menu-Driven Program to compute the area of the various geometrical shape.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.