• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
August 12, 2022 |2.5K Views
C Program to Print Number of Days in a Month
  Share   Like
Description
Discussion

In this video, we will write a C Program to Print Number of Days in a Month. 

Here we see two different methods for printing the number of days in a month. 

1. Using If-Else condition: 

Step 1: Take input month as a number N. 
Step 2: If N is one of these values 1, 3, 5, 7, 8, 10, 12, then print “31 Days”. 
Step 3: If N is one of these values 4, 6, 9, 11, then print “30 Days”. 
Step 4: If N is 2, then print “28/29 Days”. 
Step 5: Else print “Invalid Month”. 
So the time complexity is O(1) and space complexity is O(1) of this method. 

2. Using Switch case statement: 

Step 1: Get the input month as a number N. 
Step 2: Using the switch statement when the value of N is one of 1, 3, 5, 7, 8, 10, 12, then print “31 Days.” corresponding to the switch case. 
Step 3: If N is one of these values 4, 6, 9, 11, then print “30 Days.” corresponding to the switch case. 
Step 4: If N is 2, then print “28/29 Days.” corresponding to the switch case. 
Step 5: Else the default condition for the switch case will print “Invalid Month”. 
So the time complexity is O(1) and space complexity is O(1) of this method.

Example:

Input: N = 12 
Output: 31 Days 

Input: N = 4 
Output: 30 Days 

C program to print number of days in a month
https://www.geeksforgeeks.org/c-program-to-print-number-of-days-in-a-month/

Read More