C Program to Find Number of Days in a Given Month and Year

C program to find number of days in a given month and year; Through this tutorial, we will learn how to find number of days in given month and year in c program.

Algorithm to Find Number of Days in a Given Month and Year

Use the following algorithm to write a program to find number of days in a given month and year; as follows:

  • Step 1:- Start Program.
  • Step 2:- Get input month and year from user.
  • Step 3:- Check if the given month is February. 
  • Step 4:- If True Check if the year is a year leap or not.
  • Step 5:- If year is a leap year Print 29 Days, Else Print 28 Days.
  • Step 6:- If Condition in Step 3 is False Check the month. 
  • Step 7:- Print the number of days assigned to specific Month.
  • Step 8:- End Program.

C Program to Find Number of Days in a Given Month and Year

#include<stdio.h>
int main()
{
    int month, year;
    printf("enter the month : ");
    scanf("%d",&month);
    printf("enter the year : ");
    scanf("%d",&year);
    if(((month==2) && (year%400==0)) || ((year%100!=0)&&(year%4==0)))
    {
        printf("Number of days is 29");
    }
    else if(month==2)
    {
        printf("Number of days is 28");
    }
    else if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)
    {
        printf("Number of days is 31");
    }
    else
    {
        printf("Number of days is 30");
    }
    return 0;
}

The output of the above c program; as follows:

enter the month : 2
enter the year : 2022
Number of days is 28

Recommended C Programs

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *