Write a C C++ program to find number of days in a month

 

Flowchart

Flowchart to find number of days in months

 

Coding in C

#include<stdio.h>
int main()
{
int month;
printf(“Enter month number: “);
scanf(“%d”,&month);
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
printf(“31 days”);
break;
case 4:
case 6:
case 9:
case 11:
printf(“30 days”);
break;
case 2:
printf(“28 days”);
break;
default:
printf(“Invalid month number”);
}
return 0;
}

 

Coding in C++

#include<iostream>
using namespace std;
int main()
{
int month;
cout<<“Enter month number: “;
cin>>month;
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
cout<<“31 days”;
break;
case 4:
case 6:
case 9:
case 11:
cout<<“30 days”;
break;
case 2:
cout<<“28 days”;
break;
default:
cout<<“Invalid month number”;
}
return 0;
}

 

Output

Number of days in months program output

 

Published by

admin

I am a computer teacher, programmer and web developer