#include
#include
#include
#define TRUE 1
#define FALSE 0
int toint(char *s);
int isleap(int year);
int check(int year,int month,int day);
void func(int year,int month,int day);
int main(int argc, char **argv)
{
int days[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int day,y,m,d;
if(4!=argc)
{
printf("please input year,month,day: ");
scanf("%d %d %d", &y, &m, &d);
}
else
{
y = toint(argv[1]);
m = toint(argv[2]);
d = toint(argv[3]);
}
if(check(y,m,d))
{
printf("%d %d %d\n", y,m,d);
func(y,m,d);
}
return 0;
}
int toint(char *s)
{
int ret=0;
char *tmp=s;
while('\0'!=*tmp)
{
ret=ret*10+*tmp-'0';
}
return ret;
}
int isleap(int year)
{
if(((year%4==0)&&(year%100==0))||(year%400==0))
{
return TRUE;
}
return FALSE;
}
int check(int year,int month,int day)
{
int days[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if(isleap(year))
{
days[2]=29;
}
if(year<0)
{
return FALSE;
}
if(month<1||month>12)
{
return FALSE;
}
if(day>days[month])
{
return FALSE;
}
return TRUE;
}
void func(int y,int m,int d)
{
int i, day=0;
int days[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if(isleap(y))
{
days[2]=29;
}
for(i=0;i {
day+=days[i];
}
day+=d;
printf("%d %d %d is the %d day.\n", y,m,d,day);
}
阅读(1390) | 评论(0) | 转发(0) |