Please login

Prime

Prepinsta Prime

Video courses for company/skill based Preparation

(Check all courses)
Get Prime Video
Prime

Prepinsta Prime

Purchase mock tests for company/skill building

(Check all mocks)
Get Prime mock

C Program to count the number of days in a given month of a year

Number of days in a given month of a given year


 

Number of days in any month of a year can vary specifically in February as the cycle of leap year repeats in every 4 years when the year is leap February gives the count to 29 days but the when the year is not leap it gives count to 28 days and so no of days in a year varies from 365 to 366. 
Rather than February every month gives the count of 30 or 31 days in any case whether the year is a leap or not.

Python program to count number of days in a given month of a year

Algorithm

  • Step 1:- Start.
  • Step 2:- Take user inputs like month and year.
  • 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.

C Program for number of days

#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%4==0)) || ((year%100==0)&&(year%400==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;
}