Tuesday 29 March 2016

Program to find out number of days in a month using switch case conditon in c++ language.

//WAP to find out number of days in a month using switch case.

#include<iostream.h>
#include<conio.h>

void main()
{

clrscr();
int m,y;
cout<<"enter month no."<<endl;
cin>>m;
cout<<"enter year"<<endl;
cin>>y;
switch(m)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:

cout<<"No of days in this month is 31"<<endl;
break;

case 4:
case 6:
case 9:
case 11:

cout<<"No of days in this month is 30"<<endl;
break;
case 2: 

if(y%4==0)
{

cout<<"it is a leap year"<<endl;
cout<<"so no of days is 29"<<endl;
}
else
cout<<"no of days in a month is 28"<<endl;
break;
default:
cout<<"error"<<endl;
break;
}
getch();
}


Output:-
            

No comments:

Post a Comment