慕的地5574907
2019-09-20 15:01
#include <stdio.h>
int main()
{ /* 定义需要计算的日期 */
int year = 2008;
int month = 8;
int day = 8;
/*
* 请使用switch语句,if...else语句完成本题
* 如有想看小编思路的,可以点击左侧任务中的“不会了怎么办”
* 小编还是希望大家独立完成哦~
*/
int i, daysum =0;
if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0){
i = 1;
}else
i = 0;
switch(month){
case 12:daysum += 30;
case 11:daysum += 31;
case 10:daysum += 30;
case 9:daysum += 31;
case 8:daysum += 31;
case 7:daysum += 30;
case 6:daysum += 31;
case 5:daysum += 30;
case 4:daysum += 31;
case 3:daysum += 28 + i;
case 2:daysum += 30;
case 1:daysum += day;break;
default:printf("dates error!\n");
}
printf("%d年%d月%d日是该年的第%d天。\n", year, month, day, daysum);
return 0;
}
case 2:daysum += 30 应该31
一月大,二月平,三月大。。。
#include <stdio.h>
int main()
{
/* 定义需要计算的日期 */
int year = 2008;
int month = 8;
int day = 8;
int k,daysum=0;
if(year%4 ==0 && year%100 !=0){
k = 1;
}else{
k = 0;
}
switch(month)
{
case 12:daysum += 30;
case 11:daysum += 31;
case 10:daysum += 30;
case 9:daysum += 31;
case 8:daysum += 31;
case 7:daysum += 30;
case 6:daysum += 31;
case 5:daysum += 30;
case 4:daysum += 31;
case 3:daysum += 28 + k;
case 2:daysum += 31;
case 1:daysum += day;break;
default:printf("一年只有十二个月\n");
}
printf("%d年%d月%d日是该年的第%d天。\n", year, month, day, daysum);
return 0;
}
#include <stdio.h>
int main()
{
int year = 2008;
int month = 8;
int day = 8;
int i=0,daysum=0;
if( year%4==0 && year%100!=0 || year%400==0 )
i = 1;
switch(month){
case 12:daysum += 31;
case 11:daysum += 31;
case 10:daysum += 30;
case 9:daysum += 31;
case 8:daysum += 31;
case 7:daysum += 30;
case 6:daysum += 31;
case 5:daysum += 30;
case 4:daysum += 31;
case 3:daysum += 28 + i;
case 2:daysum += 31;
case 1:daysum += day;break;
default:printf("dates error!\n");
}
printf("%d年%d月%d日是该年的第%d天。\n", year, month, day, daysum);
return 0;
}
C语言入门
926206 学习 · 20797 问题
相似问题