C语言编程不知道错在哪里 10
我想计算2017年的日期,以2014年1月1日是星期三算起,不知为何变量totalday始终是初始值0,求改善#include<stdio.h>voidmain(){in...
我想计算2017年的日期,以2014年1月1日是星期三算起,不知为何变量totalday始终是初始值0,求改善
#include<stdio.h>
void main()
{ int year,month,day,week;
int err=0;
int i;
int totalday=0;
printf("请输入年,月,日:");
scanf("%d%d%d",&year,&month,&day);
i=year-2014;
while(i>0)
{ if((i+2013)%4==0&&(i+2013)%100!=0||(i+2013)%400==0)
totalday+=366;
else
totalday+=365;
i--;
}
while (i=0)
{ switch(month-1)
{ case 11:totalday+=30;
case 10:totalday+=31;
case 9: totalday+=30;
case 8: totalday+=31;
case 7: totalday+=31;
case 6: totalday+=30;
case 5: totalday+=31;
case 4: totalday+=30;
case 3: totalday+=31;
case 2: if(year% 4==0&&year% 100!=0||year% 400==0)
totalday+=29;
else
totalday+=28;
case 1: totalday+=31;
case 0: totalday+=day;break;
default:printf("输入错误!");
err=1;
}
}
if (err==0)
week=(totalday+3)%7;
printf("%d年%d月%d日是星期%d\n",year,month,day,week);
}
/*不知为何totalday始终是0,求老师解答!*/ 展开
#include<stdio.h>
void main()
{ int year,month,day,week;
int err=0;
int i;
int totalday=0;
printf("请输入年,月,日:");
scanf("%d%d%d",&year,&month,&day);
i=year-2014;
while(i>0)
{ if((i+2013)%4==0&&(i+2013)%100!=0||(i+2013)%400==0)
totalday+=366;
else
totalday+=365;
i--;
}
while (i=0)
{ switch(month-1)
{ case 11:totalday+=30;
case 10:totalday+=31;
case 9: totalday+=30;
case 8: totalday+=31;
case 7: totalday+=31;
case 6: totalday+=30;
case 5: totalday+=31;
case 4: totalday+=30;
case 3: totalday+=31;
case 2: if(year% 4==0&&year% 100!=0||year% 400==0)
totalday+=29;
else
totalday+=28;
case 1: totalday+=31;
case 0: totalday+=day;break;
default:printf("输入错误!");
err=1;
}
}
if (err==0)
week=(totalday+3)%7;
printf("%d年%d月%d日是星期%d\n",year,month,day,week);
}
/*不知为何totalday始终是0,求老师解答!*/ 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询