这个程序是我自己写的,比较繁琐,但算法还是比较简单的,楼主可以在我的基础上加以改进。
#include "iostream.h"
#include "stdio.h"
#define COUNT
printf("It is error!\n")
int NoLeap_day(int year);
int Leap_day(int year);
struct date
{
int year;
int months[2][13];
int day;
}DATE;
void main()
{
struct date DATE;
struct date *p;
p=&DATE;
int Dayst;
cin>>p->year;
if((p->year%100!=0)&&(p->year%4==0)||(p->year%400==0))
{
Dayst=Leap_day(p->year);
}
else
{
Dayst=NoLeap_day(p->year);
}
}
int Leap_day(int year)
{
int i,month,day,Dayst,months[2][13]={{0,31,29,31,30,31,30,31,31,30,31,30,31},{0,31,28,31,30,31,30,31,31,30,31,30,31}};
cin>>month>>day;
Dayst=0;
if(month<=12)
{
if(day>months[0][month])
{
return COUNT;
}
else
{
for(i=0;i<month;i++)
{
Dayst+=months[0][i];
}
Dayst+=day;
return
printf("The day is the %d day.",Dayst);
}
}
else return COUNT;
}
int NoLeap_day(int year)
{
int i,month,day,Dayst,months[2][13]={{0,31,29,31,30,31,30,31,31,30,31,30,31},{0,31,28,31,30,31,30,31,31,30,31,30,31}};
cin>>month>>day;
Dayst=0;
if(month<=12)
{
if(day>months[0][month])
{
return COUNT;
}
else
{
for(i=0;i<month;i++)
{
Dayst+=months[1][i];
}
Dayst+=day;
return
printf("The day is the %d day.",Dayst);
}
}
else return COUNT;
}