Number Of Days In A Given Month Of A Given Year

Number of days in a given month of a given year:

The C program helps to find number of days in a month. As we all know, there are 12 months in a year and some months have 31 days and others 30, except February, having 28 days or 29 days (leap year). The number of days in a year however depends upon the year. Let us use the C program to find number of days in a specific month in a given year.

Algorithm to find number of days in a given month of a year:

Step 1: Start

Step 2: The user is asked to insert month and year as an input.

Step 3: If the year is leap year and (month = = 2), i.e. February, then display “No. of days is 29”.

Step 4: If the case is not the same as the above step, else if (month = = 2), show “No. of days 28”.

Step 5: Else if ((month = = 1) || (month = = 3 || (month = = 5) (month = = 7) || (month = = 8) || (month = = 10) (month = = 12), show “No. of days is 31”.

Step 6: If not then, display “No. of days is 30”.

Program to find number of days in a given month of a year:

// C program to find the no. of days in a given month
#include <stdio.h>
int main() { //fill the code int year, month; scanf("%d %d",&month,&year); if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) printf("No. of days is 31"); else if((month == 2) && (year%4 == 0) || ((year%100 == 0) &&(year%400 == 0))) { printf("Number of days is 29"); } else if(month == 2) { printf("No. of days is 28"); } else printf("No. of days is 30"); return 0; }

Output

2
2004
No. of days is 29