tuzib263629491
2016-07-14 11:38
#include <stdio.h>
int main()
{
/* 定义需要计算的日期 */
int year = 2008;
int month = 8;
int day = 8;
/*
* 请使用switch语句,if...else语句完成本题
* 如有想看小编思路的,可以点击左侧任务中的“不会了怎么办”
* 小编还是希望大家独立完成哦~
*/
if(year%4!=0||year%100==0||year%400!=0)
{
switch(day)
{
case 1:
printf("%d",day);
break;
case 2:
printf("%d",day=31+day);
break;
case 3:case 5:case 7:case 9:case 11:
printf("%d",day=59+(month-1)/2*31+(month-3)/2*30+day);
break;
case 8:
printf("%d",day=213+day);
break;
case 10:case 12:
printf("%d",day=59+month/2*31+(month-3)/2*30+day);
break;
}
}
else
{
switch(day)
{
case 1:
printf("%d",day);
break;
case 2:
printf("%d",day=31+day);
break;
case 3:case 5:case 7:case 9:case 11:
printf("%d",day=60+(month-1)/2*31+(month-3)/2*30+day);
break;
case 8:
printf("%d",day=214+day);
break;
case 10:case 12:
printf("%d",day=60+month/2*31+(month-3)/2*30+day);
break;
}
}
return 0;
}
1.当我把8号改成7号,221天变成了219天
2.把8月改成7月,结果没变
3.把2008年改成2020年,运行不出东西
求解答
#include <stdio.h> int main() { int year = 2008; int month = 3; int day = 1; int i,j; if(year%400==0||(year%4==0&&year%100!=0))i=1; else i=0; switch(month) { case 1:j=day;break; case 2:j=31+ day;break; case 3:j=31+ 28+ day;break; case 4:j=31+ 28+ 31+ day;break; case 5:j=31+ 28+ 31+ 30+ day;break; case 6:j=31+ 28+ 31+ 30+ 31+ day;break; case 7:j=31+ 28+ 31+ 30+ 31+ 30+ day;break; case 8:j=31+ 28+ 31+ 30+ 31+ 30+ 31+day;break; case 9:j=31+ 28+ 31+ 30+ 31+ 30+ 31+ 31+ day;break; case 10:j=31+ 28+ 31+ 30+ 31+ 30+ 31+ 31+ 30+day;break; case 11:j=31+ 28+ 31+ 30+ 31+ 30+ 31+ 31+ 30+ 31+day;break; case 12:j=31+ 28+ 31+ 30+ 31+ 30+ 31+ 31+ 30+ 31+ 30+ day;break; } if(i==1&&month>=3)j+=1; else j+=0; printf("%d年%d月%d日是该年的第%d天",year,month,day,j); return 0; }
#include <stdio.h> int main() { int year = 2008; int month = 8; int day = 8; int i,j; if(year%400==0||(year%4==0&&year%100!=0))i=1; else i=0; switch(month) { case 1:j=day;break; case 2:j=31+ day;break; case 3:j=31+ 28+ day;break; case 4:j=31+ 28+ 31+ day;break; case 5:j=31+ 28+ 31+ 30+ day;break; case 6:j=31+ 28+ 31+ 30+ 31+ day;break; case 7:j=31+ 28+ 31+ 30+ 31+ 30+ day;break; case 8:j=31+ 28+ 31+ 30+ 31+ 30+ 31+day;break; case 9:j=31+ 28+ 31+ 30+ 31+ 30+ 31+ 31+ day;break; case 10:j=31+ 28+ 31+ 30+ 31+ 30+ 31+ 31+ 30+day;break; case 11:j=31+ 28+ 31+ 30+ 31+ 30+ 31+ 31+ 30+ 31+day;break; case 12:j=31+ 28+ 31+ 30+ 31+ 30+ 31+ 31+ 30+ 31+ 30+ day;break; } if(i==1&&j>=61)j+=1; else j+=0; printf("%d年%d月%d日是该年的第%d天",year,month,day,j); return 0; }
这条路很艰难的,,,你要挺住啊。。。。
记住不会就问啊,,不要不会自己在那苦恼。。。。。
这是我写的代码,你看下:
#include <stdio.h>
int main()
{
/* 定义需要计算的日期 */
int year = 2200;
int month = 8;
int day = 8;
int sum = 0; //记录天数。。
/*
* 请使用switch语句,if...else语句完成本题
* 如有想看小编思路的,可以点击左侧任务中的“不会了怎么办”
* 小编还是希望大家独立完成哦~
*/
if(month>0&&month<=12)
{
switch(month)
{
case 1:sum=day;break;
case 2:sum=day+31;break;
case 3:sum=day+31+28;break;
case 4:sum=day+31+28+31;break;
case 5:sum=day+31+28+31+30;break;
case 6:sum=day+31+28+31+30+31;break;
case 7:sum=day+31+28+31+30+31+30;break;
case 8:sum=day+31+28+31+30+31+30+31;break;
case 9:sum=day+31+28+31+30+31+30+31+31;break;
case 10:sum=day+31+28+31+30+31+30+31+31+30;break;
case 11:sum=day+31+28+31+30+31+30+31+31+30+31;break;
case 12:sum=day+31+28+31+30+31+30+31+31+30+31+30;break;
default:
printf("恭喜您脑子进水了");break;
}
if((year%4==0&&year%100!=0)||year%400==0)
{
sum+=1;
}
else
{
sum+=0;
}
printf("%d年%d月%d日是该年的%d天",year,month,day,sum);
}
else
{
printf("%s","恭喜您脑子进水了。。");
}
return 0;
}
错误很多。。。。你最好重新写一遍。。。。。
你这段代码的逻辑非常混乱。。。。。
建议重新梳理。。。
骚年,你看这里
switch(day)
懂了没。。。
闰年判断条件应该是year%4==0&&year%100!=0||year%400==0
C语言入门
926210 学习 · 20797 问题
相似问题