2

C Program to Print Number of Days in a Month

 1 year ago
source link: https://www.geeksforgeeks.org/videos/c-program-to-print-number-of-days-in-a-month/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

C Program to Print Number of Days in a Month

C Program to Print Number of Days in a Month
Hello everyone. Welcome to the grief for geeks. My name
  • 12/08/2022

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/


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK