首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

小程序(作业)如何错的呀?分析下三条语句`

2012-02-21 
小程序(作业)怎么错的呀?分析下三条语句`~~#include stdio.h main()/*输入年,月,日计算该日期是这年的第

小程序(作业)怎么错的呀?分析下三条语句`~~
#include "stdio.h "
main()/*输入年,月,日计算该日期是这年的第几天*/
{int   n;
    int   year,month,date,days=0;

            printf( "please   input   year,month,date:\t ");

scanf( "%d,%d,%d ",&year,&month,&date);

int   a[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
/*这一句说是表达式语法错误,我是按书上说的,对照了半天都没有看出错误来*/

  for(n=0;n <month;n++)

      {if((year%4==0&&year%400!=0)||(year%400==0))
 
            days+=a[1][n];   /*这句是未定义的符号a,可是我不是定义了数组a   了吗   ?*/

                  else   days+=a[0][n];}/*这句为无效间接操作错误*/

                        days+=date;

          printf( "the   days   are:\t%d ",days);
}




[解决办法]
在Turbo C for Windows中你把int a[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
这句放到前面定义即可
但是你的程序好像有问题
如果是month=1,那么days必然超过31

热点排行