慕瓜3168352
2019-06-02 20:27
#include <stdio.h>
int main()
{
/* 定义需要计算的日期 */
int year = 2008;
int month = 8;
int day = 8;
int sum =0;
int er =0;
switch(month)
{
if(year%4==0&&year%400==0)
{
er=29;
}else
er=28;
case 1:
sum +=day;
case 2:
sum +=day+31;
case 3:
sum +=day+er+31;
case 4:
sum +=day+er+31+31;
case 5:
sum +=day+er+31+31+30;
case 6:
sum +=day+er+31+31+30+31;
case 7:
sum +=day+er+31+31+30+31+30;
case 8:
sum +=day+er+31+31+30+31+30+31;
case 9:
sum +=day+er+31+31+30+31+30+31+30;
case 10:
sum +=day+er+31+31+30+31+30+31+30+31;
case 11:
sum +=day+er+31+31+30+31+30+31+30+31+30;
case 12:
sum +=day+er+31+31+30+31+30+31+30+31+30+31;
printf("在计算润年的时候,%d月是%d天",month,sum);
}
return 0;
}
#include <stdio.h>
int main()
{
/* 定义需要计算的日期 */
int year = 2008;
int month = 8;
int day = 8;
int sum =0;
/*
* 请使用switch语句,if...else语句完成本题
* 如有想看小编思路的,可以点击左侧任务中的“不会了怎么办”
* 小编还是希望大家独立完成哦~
*/
for(int i=1;i<=month;i++){
if(i == month){
sum += day;
}else
if(i == 1 || i ==3 || i ==5|| i ==7 || i ==8 || i ==10 || i ==12){
sum+=31;
}else if(year%4==0 && i==2 ){
sum+=29;
}else if(year%4!=0 && i==2 ){
sum += 28;
}else{
sum += 30;
}
}
printf("%d年%d月%d日是该年的第%d天",year,month,day,sum);
return 0;
}
兄弟 这样写不累吗。。。。。
C语言入门
926207 学习 · 20797 问题
相似问题