c语言实现日历表
#include <iostream>
using namespace std;
#define calendar 35
#define M 100
int isgrid(int a[], int b, int c);
bool isYaer(int year) {//判斷閏年if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {return true;}else {return false;}
}
void printCanlendar(int year, int mon) {int a[12] = { 31, 28, 31, 30, 31, 30 ,31, 31, 30, 31, 30, 31 };char day[7][20] = { {"Monday"},{"Tuesday"}, {"Wednesday"}, {"Thursday"}, {"Friday"}, {"Saturday"}, {"Sunday"}};int bData[367] = { 0 };int count = 0;int interval = (mon - 1) * calendar;//根據月份讓數組從不同位置輸出int model = 0;int lattice = ((year - 1901) % 7 + 1 + (year - 1901) / 4) % 7;//計算出1901年往后的每一年一月份前面的空格if (isYaer(year)) {a[1] = 29;}
//把日歷的數值賦值給數組for (int i = 0; i < 12; i++) {for (int j = 0; j < a[i]; j++) {bData[count++] = j + 1;}}if (1 != mon) {interval -= isgrid(bData, mon, lattice) * 7;//矯正輸出位置}//打印日歷表標題for (int i = 0; i < 7; i++) {printf("%s", day[i]);}//打印日歷表for (int i = interval - lattice; i < (calendar + interval - lattice + 7) && i < 366; i++, model++) {if (model % 7 == 0) {printf("\n");}if (i < 0) {printf(" \t");continue;}printf("%d \t", bData[i]);}
}
int isgrid(int bData[],int mon, int lattice) {int sum = 0;int ismon = 1;for (int i = 35 - lattice - 1; i < 367 && ismon < mon; ) {if (bData[i] > 10) {i += 35;ismon++;}else {sum++;i += 28;ismon++;}}return sum;
}
int main() {printCanlendar(2014, 7);
}
怕什么真理無窮,進一寸有進一寸的歡喜 -胡適
總結
- 上一篇: 菜鸟爬取中关村手机详情页参数及报价
- 下一篇: 《计算机科学与探索,《计算机科学与探索》