# 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 in C++

Here, in this page we will discuss the program to find the number of days in a given month of a given year in C++ .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.

## Algorithm

• Take user inputs like month and year.
• Check if the given month is February.
• If True Check if the year is a year leap or not.
• If year is a leap year Print 29 Days, Else Print 28 Days.
• If Condition in Step 3 is False Check the month.
• Print the number of days assigned to specific Month.

### C++ Code:-

`    //C++ program    //to display number of days in a month    #include<bits/stdc++.h>    using namespace std;    //main Program    int main()    {        //take user inputs for Month and year in integer        int Month,Year;        cout<<"\nEnter the Month :";        cin>>Month;        cout<<"\nEnter the Year :";        cin>>Year;        //Check condition for Month and leap year        if(Month == 2 && (Year%400 == 0) || ((Year%100 != 0) && (Year%4 == 0)))            cout<<"Number of days is 29";        else if(Month == 2)            cout<<"Number of days is 28";        else if(Month == 1 || Month == 3 || Month == 5 || Month == 7 || Month == 8 || Month == 10 || Month == 12)            cout<<"Number of days is 31";        else            cout<<"Number of days is 30";    }`
`Output:    Enter the Month :2    Enter the Year :2012    Number of days is 29`
• Highest Common Factor(HCF): C | C++Java | Python
• Lowest Common Multiple (LCM) : C | C++ | Java | Python
• Greatest Common Divisor : C | C++ | Java | Python
• Binary to Decimal to conversion : C | C++ | Java | Python
• Binary to Octal conversion : C | C++ | Java  | Python
• Decimal to Binary conversion: C | C++ | Java | Python
• Decimal to octal Conversion: C | C++ | Java | Python
• Octal to Binary conversion : C | C++ | Java | Python
• Octal to Decimal conversion : C | C++ | Java | Python
• Quadrants in which a given coordinate lies : C | C++ | Java | Python
• Permutations in which n people can occupy r seats in a classroom : C | C++ | Java | Python
• Maximum number of handshakes: C | C++ | Java | Python
• Addition of two fractions: C | C++ | Java | Python
• Replace all 0’s with 1 in a given integer : C | C++ | Java | Python
• Can a number be expressed as a sum of two prime numbers : C | C++ | Java | Python
• Count possible decoding of a given digit sequence : C | C++ | Java
• Check whether a character is a vowel or consonant : C | C++ | Java | Python
• Check whether a character is a alphabet or not : C | C++ | Java | Python
• Calculate the area of a circle : C | C++ | Java | Python
• Find the ASCII value of a character : C | C++ | Java | Python
• Find the prime numbers between 1 to 100 : C | C++ | Java | Python
• Calculate the number of digits in an integer : C | C++ | Java | Python
• Convert digit/number to words : C | C++ | Java | Python
• Counting number of days in a given month of a year: C | C++ | Java | Python
• Finding Number of times x digit occurs in a given input : C | C++ | Java | Python
• Finding number of integers which has exactly x divisors: C | C++ | Java | Python
• Finding Roots of a quadratic equation : C | C++ | Java | Python