首先要判断这年是不是闰年
将每月的月份存储到int数组中可以方便处理
实现程序如下:
#include "iostream"
using namespace std;
int main()
{
int year,days; //input year and days
int months[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int month=1,day=1;
cin>>year>>days;
if((year<0) || (days < 0))
{
cout<<"year or days error"<=0)
{
if(days > months[month-1])
{
days-=months[month-1];
month+=1;
}
else
{
day = days;
break;
}
}
cout<<"日期为:"<