about-text

SoftOSet is the most remarkable programming site. SoftOSet provides the fresh conceptual and professional programs, articles, books, and other interesting and technical writings. SoftOSet is the most reliable programming site to learn the programs and the basics of the popular programming languages. SoftOSet is the hub of the informative and research based articles.

C Program to find Number of Days in Month

 

 

                 

 

C program are an important way to solve the mathematical problems and are used in other important applications. As you know that C is very smart and magnificent language and such sort of calculation can easily be done in C Language.

C Program on Execution

We will develop such a C program, which will the month and year from user to find the number of days in month. User has to be asked to enter the month and the year. When user will give the month and year the program will provide the number of days of desired month.

 

Back End Programming

In main function of program we will declare three integer type variables days, month and year. User choice will be taken using the input statements cin>>month; and cin>>year. Then using conditional operators will be used to clear the logic of the program.

 


Conditional Operators used

Ø  If year is leap and month is February then days will be 29, else for every other year days of February will be 28.

Ø  If month is November, April, June or September, the number of days will be 30.

Ø  For all other cases the months will have 31 days.

We have to just convert this logic into the C++ statements.

 

Code

 

//date 1 february 2019;

//program to find the number of days in a month

#include<iostream>

using namespace std;

int main()

{

            int year,month,days;

            cout<<"Enter the Month\n"<<endl;

            cin>>month;

           

                        cout<<"Enter the Year\n"<<endl;

            cin>>year;

           

            if(month==4||month==6||month==9||month==11)

            {

                        cout<<"There are 30 Days in the month no "<<month<<" of "<<year<<endl;

            }

            else if(month==2)

            {

                        if(year%4==0)

                        cout<<"There are 29 Days in the month no "<<month<<" of "<<year<<endl;

                        else

                                    cout<<"There are 28 Days in the month no "<<month<<" of "<<year<<endl;

            }

            else if(month==1||month==3||month==5||month==7||month==8||month==12)

            {

                        cout<<"There are 31 Days in the month no"<<month<<" of "<<year<<endl;

            }

            else

            cout<<"There are only Twelve Months in"<<year<<"\nAnd"<<month<<"is not any Month of "<<year<<endl;

            return 0;

}

 

 

Output

The sample run of this program will yield the following output.

 

 

 

 

 

 

 

 

Please inform us you If you have any problem regarding to this code or you have any type of problem with any other code. That’s it.

Thanks for visiting this website.

 


Post a Comment

Feel Free to Comment Us

Previous Post Next Post

Recents