慕先生9555170
2019-08-10 14:24
#include <stdio.h>
int main()
{
/* 定义需要计算的日期 */
int year = 2008;
int month = 8;
int day = 8;
int today=0;
/*
* 请使用switch语句,if...else语句完成本题
* 如有想看小编思路的,可以点击左侧任务中的“不会了怎么办”
* 小编还是希望大家独立完成哦~
*/
if(year%4==0)
{
switch(month)
{
case 12:today+=30;
case 11:today+=29;
case 10:today+=30;
case 9:today+=29;
case 8:today+=30;
case 7:today+=30;
case 6:today+=29;
case 5:today+=30;
case 4:today+=29;
case 3:today+=30;
case 2:today+=29;
case 1:today+=day;
break;
printf("今日是%d年的第%d天",year,today);
}
else
{
switch(month)
{
case 12:today+=30;
case 11:today+=29;
case 10:today+=30;
case 9:today+=29;
case 8:today+=30;
case 7:today+=30;
case 6:today+=29;
case 5:today+=30;
case 4:today+=29;
case 3:today+=30;
case 2:today+=28;
case 1:today+=day;
break;
printf("今日是%d年的第%d天",year,today);
}
}
}
#include <stdio.h>
int main()
{
/* 定义需要计算的日期 */
int year = 2008;
int month = 8;
int day = 8;
/*
* 请使用switch语句,if...else语句完成本题
* 如有想看小编思路的,可以点击左侧任务中的“不会了怎么办”
* 小编还是希望大家独立完成哦~
*/
return 0;
}
你改成这样比较好。
#include <stdio.h>
int main()
{
int year = 2008;
int month = 8;
int day = 8;
int today=0,r=0,yue=month;
if((year%4==0&&year%100!=0)||year%400==0)
r=1;
switch(yue-1)
{
case 11:today+=30;
case 10:today+=31;
case 9:today+=30;
case 8:today+=31;
case 7:today+=31;
case 6:today+=30;
case 5:today+=31;
case 4:today+=30;
case 3:today+=31;
case 2:today+=28+r;
case 1:today+=31;
case 0:today+=day;
break;
}
printf("%d年%d月%d日是该年的第%d天",year,month,day,today);
return 0;
}
if少了个括号,return 0;没写 还有程序的算法部分是错的
C语言入门
926210 学习 · 20797 问题
相似问题