呵呵 帮优化优化阿 呵呵 谢谢啦
#include<stdio.h> int leap(int year) { if( (year%4==0&&year%100!=0)||(year%400==0) ) return 1; else return 0; } int leftdays1(int year1,int year2) { int a; int days=0; for(a=1;a<(year2-year1);a++) days+=(365+leap(year1+a) ); return days; } int leftdays2(int month,int year) { int sum=0; int i; int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; for(i=0;i<month;i++) sum+=d[month]; if( leap(year) && month>2 ) sum+=1; return sum; } main() { int b_year,b_month,b_day; int o_year,o_month,o_day; int totaldays; int a,b,c; int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; clrscr(); printf("please input the begin date with space\n"); scanf("%d %d %d",&b_year,&b_month,&b_day); printf("please input the end date\n"); scanf("%d %d %d",&o_year,&o_month,&o_day); a=leftdays1(b_year,o_year); b=leftdays2(o_month,o_year)+o_day; c=365+leap(b_year)-leftdays2(b_month+1,b_year); totaldays=a+b+c+d[b_month]-b_day; if(leap(b_year)&&b_month==2) totaldays+=1; printf("There are %d days left\n",totaldays); getch(); }