#include "stdafx.h" int day_of_year(int year, int month, int day); int _tmain(int argc, _TCHAR* argv[]) { int year = 0, month = 0, day = 0; printf("please input year month day(yyyy month day)\n"); scanf_s("%4d %2d %2d", &year, &month, &day); int DayOfYear = day_of_year(year, month, day); printf("%4d-%2d-%2d is the %d days in this year", year, month, day, DayOfYear); getchar(); } /*day_of_year: set day of year from month & day*/ static char daytab[2][13]= { {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} }; int day_of_year(int year, int month, int day) { int i, leap; if ((year % 4) == 0 && (year % 100 != 0) || (year % 400 == 0)) { leap = 1; } else { leap = 0; } for(i=1; i < month; i++) { day+= daytab[leap][i]; } set day of year from month & day return day; }