C语言从键盘上输入年份和月份,计算并输出这一年的这一月共有多少天。

#include<stdio.h>void main(){int y, n, s = 0;//定义变量scanf_s("%d-%d", &y, &n);//输入年月switch (n)//根据月份判断天数{case 1:s = 31; break;case 2:s = 28; break;case 3:s = 31; break;case 4:s = 30; break;case 5:s = 31; break;case 6:s = 30; break;case 7:s = 31; break;case 8:s = 31; break;case 9:s = 30; break;case 10:s = 31; break;case 11:s = 30; break;case 12:s = 31; break;}if (n == 2)//判断闰年2月差异{if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0)s = 29;elses = 28;}printf("%d\n", s);}

 

本文链接:https://my.lmcjl.com/post/4552.html

展开阅读全文

4 评论

留下您的评论.