//#include "stdafx.h"//If the vc++6.0, with this line.
#include "stdio.h"
#include "time.h"
struct tm *SecondDay(int y,int m,int d){
struct tm tm={0,0,0,d,m,y,};
time_t lt=mktime(&tm)+86400;
return localtime(<);
}
int main(void){
int year,month,day,n,m[12]={31,28,31,30,31,30,31,31,30,31,30,31},i;
struct tm *ptr;
while(1){
printf("Input Year, Month, Day and n(0if(scanf("%d%d%d%d",&year,&month,&day,&n),year>1900){
m[1]=28+(year%400==0 || year%4==0 && year%100);
if(month>0 && month<13 && day>0 && day<=m[month-1] && n>0 && n<=2000)
break;
}
printf("Error, redo: ");
}
for(ptr=SecondDay(year-1900,month-1,day),i=1;iptr=SecondDay(ptr->tm_year,ptr->tm_mon,ptr->tm_mday);
printf("%d %d %d\n",ptr->tm_year+1900,ptr->tm_mon+1,ptr->tm_mday);
return 0;
}
#include
using namespace std;
int s[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
class Date
{
private:
int year;
int month;
int day;
bool leap()
{
if(year%4!=0 || year%100==0 && year%400!=0)
return false;
else
return true;
}
Date add(Date today,int days)
{
Date d;
d.year=today.year;
d.month=today.month;
d.day=d.day+days;
if(d.leap()) s[2]=29;else s[2]=28;
while(d.day>s[d.month])
{
d.day=d.year-s[d.month];
d.month++;
if(d.month>12)
{
d.year++;
if(d.leap()) s[2]=29;else s[2]=28;
}
}
return d;
}
};
Date add(Date today,int days)这个 函数就是你要的功能
写个函数,逐天加吧,每加1天,判断月和年是否要进位
~
~
~