#include <stdio.h>
int is_leap(int);
int sum_day(int,int,int);
int main(int argc,char *argv[])
{
int year,month,day;
int i,leap,result = 0;
printf("please input year,month,day:");
scanf("%d,%d,%d",&year,&month,&day);
result = sum_day(year,month,day);
printf("%d/%d/%d is the %dth day in year.\n",year,month,day,result);
system("pause");
return 0;
}
int sum_day(int year, int month, int day)
{
int months[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int i,result = 0;
for (i = 0; i < month - 1; i++)
{
result += months[i];
}
result += day;
if (month >= 3)
{
if (is_leap(year))
{
result ++;
}
}
return result;
}
int is_leap(int year)
{
int result;
if ((year % 400 == 0) || (year % 4 ==0 && year % 100 != 0))
{
result = 1;
}
else
{
result = 0;
}
return result;
}
|