Header Ads Widget

C++ Program to take the value from the user as input the month number and print number of days in that month.

 

C++ Program to take the value from the user as input the month number and print number of days in that month.

Given month number , write a program to print the number of days based on the months number .

Sample input
4
Sample output

30 days

C++ Program to take the value from the user as input the month number and print number of days in that month.

The objective of the code is to print the number of days based on the month number inputted by user .

Code(C++):-
#include<bits/stdc++.h>
using namespace std;
int main()
{
int month;
cout<<"Enter the month number ";
cin>>month;
switch(month)
{
case 1:cout<<"31 days";
break;
case 2:cout<<"28 days";
break;
case 3:cout<<"31 days";
break;
case 4:cout<<"30 days";
break;
case 5:cout<<"31 days";
break;
case 6:cout<<"30 days";
break;
case 7:cout<<"31 days";
break;
case 8:cout<<"31 days";
break;
case 9:cout<<"30 days";
break;
case 10:cout<<"31 days";
break;
case 11:cout<<"30 days";
break;
case 12:cout<<"31 days";
break;
default : cout<<"Invalid Input";
}
}


Output:-

Enter the month number
4
30 days



Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-


Post a Comment

0 Comments