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:
Flowchart:
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.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework