以下是计算该年第几天的CPP代码:

主函数部分:

int main(){

int year, month, day;

cin >> year >> month >> day;

int days = DayOfYear(year, month, day);

cout << days << endl;

return 0;

}

计算部分:

int DayOfYear(int year, int month, int day){

int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};

if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)

days[1] = 29; //处理闰年

int sum = 0;

for(int i = 0; i < month - 1; i++)

sum += days[i];

sum += day;

return sum;

}