第1个回答 2012-11-06
思路:
1.先判断输入年份是否为闰年
2.判断输入的月份
3.对应于闰年和平年的月份天数
#include <iostream>
using namespace std;
bool leapYear(int year)
{
if(year%4==0&&year%100!=0||year%4==0&&year%400==0)
return true;
else
return false;
}
int main()
{
int year, month, days;
leapdays[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
unleapdays[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
printf("Enter date(yy-mm): ");
scanf("%d-%d", &year, &month);
if ( leapYear(year) )
days = leapdays[month-1]; // 闰年的月份天数
else
days = unleapdays[month-1]; // 平年的月份天数
printf("%d-%d has %d days.\n", year, month, days);
return 0;
}本回答被网友采纳