看了一个程序是这样写的:
#include "stdio.h" main() { int year,month,days,i,leap,day; static int mtable[][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}}; printf("\nInput year,month,day:"); scanf("%d,%d,%d",&year,&month,&day); leap=0; if(year%4==0&&year%100!=0||year%400==0) leap=1; days=day; for(i=1;i<month;i++) days+=mtable[leap][i]; printf("Days=%d",days); }
我改为:#include "stdio.h" main() { int year,month,days,i,leap,day; static int mtable[][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}}; printf("\nInput year,month,day:"); scanf("%d,%d,%d",&year,&month,&day); leap=0; if(year%4==0&&year%100!=0||year%400==0) leap=1; days=day; for(i=0;i<month;i++) days+=mtable[leap][i]; printf("Days=%d",days); }
运行结果是一样的,为什么他的程序非得for(i=1;i<month;i++),i=1吗?难道有什么含义吗?