Answer:
// program in C
#include <stdio.h>
int main()
{
// variable
int m,y;
int days;
// validate month
do
{
printf("Enter a month (1-12) : ");
// read month
scanf("%d",&m);
}while(m<=0 || m >12);
printf("Enter a year : ");
// read year
scanf("%d",&y);
// months in which days are 30
if (m == 4 || m == 6 || m == 9 || m == 11)
days = 30;
// if month is feb
else if (m == 2)
// month in which days are 31
else
days = 31;
// print days in the given month
printf("Number of days:%d",days);
return 0;
}
Step-by-step explanation:
Read month from user.If entered month is not from 1-12 then ask until user enter a valid month.Read year from user.After this if month is 4,6,9 or 11 then days in the month are 30.If the month is 2 then check year is leap or not.If year is leap then 29 day else 28 days.If month is other than this then days are 31.
Output:
Enter a month (1-12) : 2
Enter a year : 2008
Number of days:29