程序填空题:输入年月日,计算这一天是这一年的第多少天。
输入年月日,计算这一天是这一年的第多少天。
c
#include <stdio.h>
int main()
{
int year, month, day, daysum = 0;
scanf ("%d %d %d", );
if (month < 1 || month > 12 || day < 1 || day > 31)
{
printf ("Date Invalid!\n");
;
}
switch ()
{
case 11: daysum += 30;
case 10: daysum += 31;
case 9: daysum += 30;
case 8: daysum += 31;
case 7: daysum += 31;
case 6: daysum += 30;
case 5: daysum += 31;
case 4: daysum += 30;
case 3: daysum += 31;
case 2:
if ()
daysum += 29;
else
daysum += 28;
case 1: daysum += 31;
default: break;
}
;
printf ("%d\n", daysum);
return 0;
}
## 输入样例1:
2022 4 9
## 输出样例1:
99
## 输入样例2:
2000 3 1
## 输出样例2:
61
## 输入样例3:
1900 4 5
## 输出样例3:
95
## 输入样例4:
2022 1 15
## 输出样例4
15
## 输入样例4:
2022 13 15
## 输出样例4
Date Invalid!
答案:
第1空:&year, &month, &day
第2空:return 0
第3空:month - 1
第4空:year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)
第5空:daysum += day
c
#include <stdio.h>
int main()
{
int year, month, day, daysum = 0;
scanf ("%d %d %d", );
if (month < 1 || month > 12 || day < 1 || day > 31)
{
printf ("Date Invalid!\n");
;
}
switch ()
{
case 11: daysum += 30;
case 10: daysum += 31;
case 9: daysum += 30;
case 8: daysum += 31;
case 7: daysum += 31;
case 6: daysum += 30;
case 5: daysum += 31;
case 4: daysum += 30;
case 3: daysum += 31;
case 2:
if ()
daysum += 29;
else
daysum += 28;
case 1: daysum += 31;
default: break;
}
;
printf ("%d\n", daysum);
return 0;
}
## 输入样例1:
2022 4 9
## 输出样例1:
99
## 输入样例2:
2000 3 1
## 输出样例2:
61
## 输入样例3:
1900 4 5
## 输出样例3:
95
## 输入样例4:
2022 1 15
## 输出样例4
15
## 输入样例4:
2022 13 15
## 输出样例4
Date Invalid!
答案:
第1空:&year, &month, &day
第2空:return 0
第3空:month - 1
第4空:year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)
第5空:daysum += day