解题思路:这是最容易想到的解法,把每种情况列举出来。
注意事项:
参考代码:
#include <stdio.h>
struct Stu
{
int year;
int month;
int date;
};
int main()
{
struct Stu stu = { 0, 0, 0 };
scanf("%d%d%d", &stu.year, &stu.month, &stu.date);
if (stu.year % 400 == 0 || stu.year % 100 != 0 && stu.year % 4 == 0)
{
switch (stu.month)
{
case 1:
{
printf("%d\n", stu.date);
break;
}
case 2:
{
printf("%d\n", 31 + stu.date);
break;
}
case 3:
{
printf("%d\n", 31 + 29 + stu.date);
break;
}
case 4:
{
printf("%d\n", 31 + 29 + 31 + stu.date);
break;
}
case 5:
{
printf("%d\n", 31 + 29 + 31 + 30 + stu.date);
break;
}
case 6:
{
printf("%d\n", 31 + 29 + 31 + 30 + 31 + stu.date);
break;
}
case 7:
{
printf("%d\n", 31 + 29 + 31 + 30 + 31 + 30 + stu.date);
break;
}
case 8:
{
printf("%d\n", 31 + 29 + 31 + 30 + 31 + 30 + 31 + stu.date);
break;
}
case 9:
{
printf("%d\n", 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + stu.date);
break;
}
case 10:
{
printf("%d\n", 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + stu.date);
break;
}
case 11:
{
printf("%d\n", 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + stu.date);
break;
}
case 12:
{
printf("%d\n", 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + stu.date);
break;
}
}
}
else
{
switch (stu.month)
{
case 1:
{
printf("%d\n", stu.date);
break;
}
case 2:
{
printf("%d\n", 31 + stu.date);
break;
}
case 3:
{
printf("%d\n", 31 + 28 + stu.date);
break;
}
case 4:
{
printf("%d\n", 31 + 28 + 31 + stu.date);
break;
}
case 5:
{
printf("%d\n", 31 + 28 + 31 + 30 + stu.date);
break;
}
case 6:
{
printf("%d\n", 31 + 28 + 31 + 30 + 31 + stu.date);
break;
}
case 7:
{
printf("%d\n", 31 + 28 + 31 + 30 + 31 + 30 + stu.date);
break;
}
case 8:
{
printf("%d\n", 31 + 28 + 31 + 30 + 31 + 30 + 31 + stu.date);
break;
}
case 9:
{
printf("%d\n", 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + stu.date);
break;
}
case 10:
{
printf("%d\n", 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + stu.date);
break;
}
case 11:
{
printf("%d\n", 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + stu.date);
break;
}
case 12:
{
printf("%d\n", 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + stu.date);
break;
}
}
}
return 0;
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:610 |
printf基础练习2 (C语言代码)浏览:322 |
成绩转换 (C语言代码)浏览:1048 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:909 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:611 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:1334 |
C语言程序设计教程(第三版)课后习题8.1 (C语言代码)浏览:1292 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:583 |
简单的a+b (C语言代码)浏览:531 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:801 |