C语言题目:设计一个程序输入年月日 输出下一天的年月日

来源:百度知道 编辑:UC知道 时间:2024/06/21 20:25:46
C语言题目:设计一个程序输入年月日 输出下一天的年月日

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
using namespace std;

struct date
{
int y;
int m;
int d;
};
date tomorrow(date a);
bool isleapyear(int year);

int main()
{
date a;
scanf("%d %d %d",&a.y,&a.m,&a.d);
a=tomorrow(a);
printf("%d %d %d",a.y,a.m,a.d);
}

date tomorrow(date a)
{
int monthday[12]={31,29,31,30,31,30,31,31,30,31,30,31};;
date b=a;
monthday[2]+=isleapyear(b.y);
b.d++;
if(b.d>monthday[b.m])
{
b.d=1;
b.m++;
if(b.m==13)
{
b.m=1;
b.y++;
}
}
return b;
}
bool isleapyear(int i)
{
if (i%100!=0 && i%4==0) return 1;
if ( i%100==0 && i%400==0) return 1;
return 0;
}