#include <stdio.h>
#include <stdlib.h>
struct date{
int day;
int month;
int year;
};
int total=0;
int countday(const int *n,struct date m);
int main()
{
int y[12]={31,29,31,30,31,30,31,31,30,31,30,31};
int ch;
struct date getdate;
printf("请输入你的日期/n");
scanf("%d%d%d",&getdate.year,&getdate.month,&getdate.day);
if(getdate.month>12&&getdate.month<0)
{
printf("请输入正确的月份/n");
scanf("%d",&getdate.month);
if(getdate.day>31&&getdate.day<0)
{
printf("请重新输入,在1~31范围内/n");
scanf("%d",&getdate.day);
}
if(getdate.year%4==0 && getdate.year%100!=0 && getdate.year%400==0)
{
printf("今年是闰年/n");
ch=countday(y,getdate);
printf("从%d年头开始已经过去%d天了哦",getdate.year,ch);
}
else
{
y[1]=28;
printf("今年是平年/n");
ch=countday(y,getdate);
printf("从%d年头开始 已经过去 %d天了",getdate.year,ch);
}
return 0;
}
int countday(const int *n,struct date m)
{
int i;
for(i=0;i<m.month;i++)
total+=n[i];
total=total+m.day;
return total;
}
编译环境:VC6.0,XP