How to find Number of Days in a month

Welcome you all to the Digital Chalkie blog. Today I’m here with an article of  “How to DO It Series”. In this article, we discuss how to read a month as a number from the keyboard and print the number of days in that month. Ok, guys. Let’s move to solve it.

Analysing the problem

We know that four months of the year have 30 days and seven moths have 31 days. Alternate February has 28 or 29 days. In this case, we assume that this is not a leap year. We can interpret these data as follows.

[wpdatatable id=3 table_view=regular]

You can see that the seven month – July is a turning point of the pattern of day count and month. So the easiest way is solving this problem is divide the year into two parts using July as the dividing point. Then we can separate months as even and odd.

Flow of the solution

The flow of the solution can be written in steps as follows.

  1. Input month as a number
  2. Define is it greater than or equal or less than to 7
  3. If greater than or equal, define even numbers as 30 day months and odd numbers as 31 day months
  4. If less than, define even numbers as 31 day months and odd numbers as 30 day months
  5. When the number equals to 2, we display number of days as 28.

Here is the correct flow chart used in programming.

number of days

Final Program

According to the flow chart above, you can write the c language code easily. In here I provide you an example code for your calm. You can simply copy it and run as your program.

Number of Days of Month – Program Code
#include <stdio.h>
#include <stdlib.h>

int main()
    int month;
    printf("Enter the Number of month : ");

    if (month<=7) //In here we consider 7 months from beginning
         if (month==2)  //Check is it February
            printf("Dates for the month is 28");  //When it is February
            if (month%2==1) // Check for odd numbers
                printf("Dates for the month is 31");
                printf("Dates for the month is 30");
        if (month%2==1)  //Check for odd months after July
                printf("Dates for the month is 30");
                printf("Dates for the month is 31");
    printf("\n \n This is a program by BMaxx\@Digital Chalkie Educationl Blog \n Thank you for Join with us \n");
    return 0;

It’s time to wind up guys. I think you learn something from this article. Hit the like. Leave a comment. Share with your friends. Wish you all the best. See you sooon.

Bonomi Tharinda
Bonomi Tharinda is the Developer of the BMaxx Blog. He is a skilled web developer and graphic designer. In addition, he is an undergraduate student of a representative University in Sri Lanka. He is working as a tutor of an institute and as a part-time blogger, he will help you all to make your problems solved.Here are his social accounts and you can follow him through them.