Getting the Total Number of Days in a Month Using If-else and Switch Statements in C#
Given a number N, the task is to write a C# program to print the number of days in the Month N.
Input: N = 12
Input: N = 2
This task can be done using the following approaches:
1. Using if else statement : Appropriate month number is checked and then number of days in a month is print using else if statement. Number of days are follows :
Month = [1, 3, 5, 7, 8, 10, 12] , Number of days = 31 Month =  , Number of days = 28/29 Month = [4, 6, 9, 11] , Number of days = 30
Below is the implementation of the above approach:
2. Using Switch Condition : Same as Else if , here month number is checked and it is redirected to cases,and then number of days in a month is print. Below is the implementation of the above approach:
My Personal Notes arrow_drop_up
Please Login to comment...