C语言怎么实现简单万年历
这篇文章给大家分享的是有关C语言怎么实现简单万年历的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
创新互联主营邯山网站建设的网络公司,主营网站建设方案,成都App制作,邯山h5小程序设计搭建,邯山网站营销推广欢迎邯山等地区企业咨询
具体内容如下
#include#include int year, month; int run[12] = { 31,29,31,30,31,30,31,31,30,31,30,31 }; int ping[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 }; char week[7][10] = { "SUN","MON","TUE","WED","THU","FRI","SAT" }; bool IsLeap(int year) { if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) //判断闰年 { return true; } else { return false; } } void PrintStar() { printf("\t\t\t万年历\t\t\t\n"); printf("****************************************************\n"); for (int i = 0; i < 7; i++) { printf("%s\t", week[i]); } printf("\n"); } int DaySum(int year, int month) { int sum = 0; for (int i = 1990; i < year; i++) { if (IsLeap(i)) { sum += 366; } else { sum += 365; } } for (int i = 0; i < month - 1; i++) { if (IsLeap(year)) { sum += run[i]; } else { sum += ping[i]; } } return sum; } void PrintCal(int sum, int year, int month) { int nRes, nTmp; nRes = sum % 7+1;//前面空几格 nTmp = 7 - nRes;//从第几格开始打印 for (int i = 0; i < nRes; i++) { printf("\t"); } if (IsLeap(year)) { for (int i = 1; i < run[month - 1]+1; i++) { printf("%d\t", i); if (nTmp == i || (i - nTmp) % 7 == 0) { printf("\n"); } } printf("\n"); } else { for (int i = 1; i < ping[month - 1]+1; i++) { printf("%d\t", i); if (nTmp == i || (i - nTmp) % 7 == 0) { printf("\n"); } } printf("\n"); } } int main(void) { while (1) { scanf_s("%d %d", &year, &month); PrintStar(); PrintCal(DaySum(year, month), year, month); printf("****************************************************\n"); } return 0; }
感谢各位的阅读!关于“C语言怎么实现简单万年历”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
标题名称:C语言怎么实现简单万年历
当前地址:http://ybzwz.com/article/isjdci.html