本文主要是介绍C语言:输入某年某月某日,判断这一天是这一年的第几天,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
注意:考虑闰年:能被4整除而不能被100整除的为闰年,能被400整除而不能被3200整除的是闰年
综上,得到代码:
#include<stdio.h>
int main() {int year, month, day;int m;scanf("%d %d %d", &year, &month, &day);if (year % 4 == 0 && year % 100 != 0||year%400==0) {switch (month) {case 1:m = day;printf("%d年%d月%d日,是这一年的第%d天", year, month, day, m);break;case 2:m = 31 + day;printf("%d年%d月%d日,是这一年的第%d天", year, month, day, m);break;case 3:m = 31 + 29 + day;printf("%d年%d月%d日,是这一年的第%d天", year, month, day, m);break;case 4:m = 31 + 29 + 31 + day;printf("%d年%d月%d日,是这一年的第%d天", year, month, day, m);break;case 5:m = 31 + 29 + 31 + 30 + day;printf("%d年%d月%d日,是这一年的第%d天", year, month, day, m);break;case 6:m = 31 + 29 + 31 + 30 + 31 + day;printf("%d年%d月%d日,是这一年的第%d天", year, month, day, m);break;case 7:m = 31 + 29 + 31 + 30 + 31 + 30 + day;printf("%d年%d月%d日,是这一年的第%d天", year, month, day, m);break;case 8:m = 31 + 29 + 31 + 30 + 31 + 30 + 31 + day;printf("%d年%d月%d日,是这一年的第%d天", year, month, day, m);break;case 9:m = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + day;printf("%d年%d月%d日,是这一年的第%d天", year, month, day, m);break;case 10:m = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + day;printf("%d年%d月%d日,是这一年的第%d天", year, month, day, m);break;case 11:m = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + day;printf("%d年%d月%d日,是这一年的第%d天", year, month, day, m);break;case 12:m = 31 + 29 + 30 + 31 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + day;printf("%d年%d月%d日,是这一年的第%d天", year, month, day, m);break;}}else {switch (month) {case 1:m = day;printf("%d年%d月%d日,是这一年的第%d天", year, month, day, m);break;case 2:m = 31 + day;printf("%d年%d月%d日,是这一年的第%d天", year, month, day, m);break;case 3:m = 31 + 28 + day;printf("%d年%d月%d日,是这一年的第%d天", year, month, day, m);break;case 4:m = 31 + 28 + 31 + day;printf("%d年%d月%d日,是这一年的第%d天", year, month, day, m);break;case 5:m = 31 + 28 + 31 + 30 + day;printf("%d年%d月%d日,是这一年的第%d天", year, month, day, m);break;case 6:m = 31 + 28 + 31 + 30 + 31 + day;printf("%d年%d月%d日,是这一年的第%d天", year, month, day, m);break;case 7:m = 31 + 28 + 31 + 30 + 31 + 30 + day;printf("%d年%d月%d日,是这一年的第%d天", year, month, day, m);break;case 8:m = 31 + 28 + 31 + 30 + 31 + 30 + 31 + day;printf("%d年%d月%d日,是这一年的第%d天", year, month, day, m);break;case 9:m = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + day;printf("%d年%d月%d日,是这一年的第%d天", year, month, day, m);break;case 10:m = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + day;printf("%d年%d月%d日,是这一年的第%d天", year, month, day, m);break;case 11:m = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + day;printf("%d年%d月%d日,是这一年的第%d天", year, month, day, m);break;case 12:m = 31 + 28 + 30 + 31 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + day;printf("%d年%d月%d日,是这一年的第%d天", year, month, day, m);break;}}
}
运行结果
备注:第一次学写博客,正在努力学习c语言,在敲这道经典题时就有了写博客的想法,也是为了记录自己学习的经历,很简单的页面,如有不足还请提出来一起学习呀!
这篇关于C语言:输入某年某月某日,判断这一天是这一年的第几天的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!