#include<stdio.h>
int main(void)
{
int year,month,day,leap,i;
int sum=0,a[12]={31,29,31,30,31,30,31,31,30,31,30,31};
int b[12]={31,28,31,30,31,30,31,31,30,31,30,31};
printf(“输入年月日:\n”);
scanf(“%d%d%d”,&year,&month,&day);
if( (year % 4 == 0 )&& (year % 100 !==0)|| (year % 400==0) leap=1;
else leap=0;
if (leap==1)
for(i=1;i<month-1;i++)
sum+=b[i];
else
for(i=1;i<month-1;i++)
sum+=a[i];
sum+=day;
printf(“sum=%d\n”,sum);
return 0;
}
int main(void)
{
int year,month,day,leap,i;
int sum=0,a[12]={31,29,31,30,31,30,31,31,30,31,30,31};
int b[12]={31,28,31,30,31,30,31,31,30,31,30,31};
printf(“输入年月日:\n”);
scanf(“%d%d%d”,&year,&month,&day);
if( (year % 4 == 0 )&& (year % 100 !==0)|| (year % 400==0) leap=1;
else leap=0;
if (leap==1)
for(i=1;i<month-1;i++)
sum+=b[i];
else
for(i=1;i<month-1;i++)
sum+=a[i];
sum+=day;
printf(“sum=%d\n”,sum);
return 0;
}
解决方案
10
1.你弄反了吧,闰年的应该用a数组
2.数组下标从0开始的
2.数组下标从0开始的
40
if( (year % 4 == 0 )&& (year % 100 !==0)|| (year % 400==0) leap=1;
括号不对称,!=写成了!==
改成
if( (year % 4 == 0 )&& (year % 100 !=0)|| (year % 400==0) ) leap=1;
括号不对称,!=写成了!==
改成
if( (year % 4 == 0 )&& (year % 100 !=0)|| (year % 400==0) ) leap=1;