慕斯卡4598373
2016-05-04 22:41
#include <stdio.h>
int main()
{
/* 定义需要计算的日期 */
int year = 2008;
int month = 8;
int day = 8;
/*
* 请使用switch语句,if...else语句完成本题
* 如有想看小编思路的,可以点击左侧任务中的“不会了怎么办”
* 小编还是希望大家独立完成哦~
*/
int y;
int sum;
switch(month-1)
{
case 1:y=31;break;
case 2:y=31+28;break;
case 3:y=31+28+31;break;
case 4:y=31+28+31+30;break;
case 5:y=31+28+31+30+31;break;
case 6:y=31+28+31+30+31+30;break;
case 7:y=31+28+31+30+31+30+31;break;
case 8:y=31+28+31+30+31+30+31+31;break;
case 9:y=31+28+31+30+31+30+31+31+30;break;
case 10:y=31+28+31+30+31+30+31+31+30+31;break;
case 11:y=31+28+31+30+31+30+31+31+30+31+30;break;
case 12:y=31+28+31+30+31+30+31+31+30+31+30+31;break;
default:printf("ERROR!!!一年只有12个月!!!");break;
}
if(year%4==0&&year%100!=0&&year%400==0)
{
if(month>=2&&month<=12)
{
sum=y+day+1;
printf("%d年%d月%d日是%d天\n",year,month,day,sum);
}
else
{
sum=y+day;
printf("%d年%d月%d日是%d天\n",year,month,day,sum);
}
}
else
{
sum=y+day;
printf("%d年%d月%d日是%d天\n",year,month,day,sum);
}
return 0;
}
switch(month)
if((year%4==0&&year%100!=0)||year%400==0)
{
if(month>=2&&month<=12)
{
sum=y+day+1;
printf("%d年%d月%d日是%d天\n",year,month,day,sum);
}
else
{
sum=day;
printf("%d年%d月%d日是%d天\n",year,month,day,sum);
}
}
#include <stdio.h> int main() { /* 定义需要计算的日期 */ int year = 2008; int month = 8; int day = 8; /* * 请使用switch语句,if...else语句完成本题 * 如有想看小编思路的,可以点击左侧任务中的“不会了怎么办” * 小编还是希望大家独立完成哦~ */ int y; int sum; switch(month) { case 1:y=0;break; case 2:y=31;break; case 3:y=31+28;break; case 4:y=31+28+31;break; case 5:y=31+28+31+30;break; case 6:y=31+28+31+30+31;break; case 7:y=31+28+31+30+31+30;break; case 8:y=31+28+31+30+31+30+31;break; case 9:y=31+28+31+30+31+30+31+31;break; case 10:y=31+28+31+30+31+30+31+31+30;break; case 11:y=31+28+31+30+31+30+31+31+30+31;break; case 12:y=31+28+31+30+31+30+31+31+30+31+30;break; default:printf("ERROR!!!一年只有12个月!!!");break; } if(year%4==0&&year%100!=0||year%400==0) { if(month>=2) { sum=y+day+1; printf("%d nian%d yue%d ri %d\n",year,month,day,sum); } else { sum=y+day; printf("%d nian %d yue %dri %d\n",year,month,day,sum); } } else { sum=y+day; printf("%d nian%d yue %d ri %d\n",year,month,day,sum); } return 0; }
你比照一下看看
C语言入门
926212 学习 · 20797 问题
相似问题