Write a program that inputs any number of month of the year and displays the name and number of days of the entered month. For example, if 4 is entered for the number of month of the year, program should display “April has 30 days”.
So let’s Write Code:
Algorithm
- Start
- Input month number in a variable
- if month number is 1 then display January has 31 days and so on,
- Add conditions for the remaining 11 months
- End
Write a program that inputs any number of months of the year and displays the name and number of days of the entered month. For example, if 4 is entered for the number of months of the year, the program should display “April has 30 days”.
#include"iostream"
using namespace std;
main()
{
int no_month;
cout<<"Enter number of month of the year [1-12]?"<<endl;
cin>>no_month;
if(no_month == 1)
cout<<"January has 31 days ";
else if(no_month == 2)
cout<<"February has 28 days ";
else if(no_month == 3)
cout<<"March has 31 days ";
else if(no_month == 4)
cout<<"April has 30 days ";
else if(no_month == 5)
cout<<"May has 31 days ";
else if(no_month == 6)
cout<<"June has 30 days ";
else if(no_month == 7)
cout<<"July has 31 days ";
else if(no_month == 8)
cout<<"August has 31 days ";
else if(no_month == 9)
cout<<"September has 30 days ";
else if(no_month == 10)
cout<<"October has 31 days ";
else if(no_month == 11)
cout<<"November has 30 days ";
else if(no_month == 1)
cout<<"December has 31 days ";
}
Hope You will learn Something From Here: