用户输入年月日,计算此日期是该年的第几天
#include <stdio.h> int main(void) { int year,month,day,num; scanf("%d-%d-%d",&year,&month,&day); printf("%d",get_day(year,month,day)); return 0; } int get_day(int year,int month,int day) { int month_data[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; int month_data_leap[12] = {31,29,31,30,31,30,31,31,30,31,30,31}; if(is_leap(year)) return process(month,day,month_data_leap); return process(month,day,month_data); } int process(int month, int day,int* data) { int counts = 0,i = 1; for(i;i<month;i++){ counts += data[i]; } return counts += day; } int is_leap(int year) { if( (year%4 == 0 && year%100 != 0) || year%400 == 0) return 1; return 0; }