1解题思路:输入年,月,日。进入switch语句进行运算,最后输出即可.具体的思路及闰年判断方法详见3,4.2
#include <stdio.h>
int main()
{
int year, month, day;
int s=0;
scanf("%d%d%d", &year,&month,&day);
printf("输入的年份为:%d\n",year);
printf("输入的月份为:%d\n",month);
printf("输入的日期为:%d\n",day);
switch(month)
{
case 12: s+=30; //加上11月的30天
case 11: s+=31; //加上10月的31天
case 10: s+=30; //加上 9月的30天
case 9: s+=31;//制作不易望关注点赞
case 8: s+=31;//后续我会持续更新c及c++语言的习题
case 7: s+=30;//关注我不迷路,有不会的私信我哦
case 6: s+=31;
case 5: s+=30;
case 4: s+=31;
case 3: s+=28; //先按平年算,加上2月的28天
case 2: s+=31; //加上 1月的31天
case 1: s+=day; //加上当月天数
}
if((year%4==0 && year%100!=0 || year%400==0) && month>=3)
s++;
printf("%d\n",s);
return 0;
}
3为什么我们要将case后常量逆序着写?因为比如说你输入了一个8,编译器会直接定位到8,因为后面没有break,语句会将8后面的语句全部输出,而s+=30表示的是s=s+30,所以就是计算的到8月的总天数
4另外闰年的判别式条件是<1>输入的年份能被4整除且不能被100整除,比如1996.<2>输入的年份能被400整除。
C语言贵在积累实践,而C语言是其他语言的铺垫。人贵有恒。
最后望您点个关注,后续我会持续发c及c++的知识点及题库,关注我不迷路