C语言项目:输出日历

头文件(main.h)

#ifndef __MAIN_H__
#define __MAIN_H__
#include
#include
#include 
#include 
#define NONE		 "\033[m"
#define RED			 "\033[0;32;31m"
#define LIGHT_RED	 "\033[1;31m"
#define GREEN        "\033[0;32;32m"
#define LIGHT_GREEN  "\033[1;32m"
#define BLUE	     "\033[0;32;34m"
#define LIGHT_BLUE	 "\033[1;34m"
#define DARY_GRAY	 "\033[1;30m"
#define CYAN		 "\033[0;36m"
#define LIGHT_CYAN	 "\033[1;36m"
#define PURPLE	     "\033[0;35m"
#define LIGHT_PURPLE "\033[1;35m"
#define BROWN	     "\033[0;33m"
#define YELLOW		 "\033[1;33m"
#define LIGHT_GRAY	 "\033[0;37m"
#define WHITE		 "\033[1;37m"
#define year 2020
#define monthnum  12
int year2020[monthnum] = { 3, 6, 7, 3, 5, 1, 3 ,6, 2 ,4 ,7, 2 };
int day2020[monthnum] = { 31,29,31,30,31,30,31,30,30,31,30,31 };
#endif

主程序(源.c)

#include"main.h"
void put(int n1,int m) {
	static int n = 1;
	char* mon[] = { "mon","tue","wed","thu","fri","sat","sun" };
	if (n%2==1) {
		printf("%d年%d月\t\t\t日历",n1,m);
		printf("\n******************************************************************\n");
		for (int i = 0; i < 7; i++) {
			printf("\t%s", mon[i]);
		}
		printf("\n");
	}
	else {
		printf("\n******************************************************************\n");
	}
	n++;
	
}
void valueout(int n,int m) {
	time_t timep;
	struct tm* p;
	char time1[28];
	time(&timep);
	p = gmtime(&timep);
	int wek1, day,day1,nowyear=1900 + p->tm_year,nowmon=1 + p->tm_mon,nowday=p->tm_mday;
	if (n % 400 == 0 || (n % 4 == 0 && n % 100 != 0)) {
		wek1 = (year2020[m - 1] + (n - 2020) / 4 + n - 2020) % 7;
		day = day2020[m - 1];
	}
	else {
		if (m > 2) {
			wek1 = (year2020[m - 1] + n - 2020) % 7;
		}
		else {
			wek1 = (year2020[m - 1] + n - 2019) % 7;
		}
		day = day2020[m - 1];
		if (m == 2)
			day--;
		
	}
	day1 = day2020[(m - 2+12)%12];
		if (m-1 == 2)
			day1--;
		day1 -= (wek1==0?7:wek1)-2;
		printf("%d %d", day1,wek1);
	for (int i = 1, o = 1; day; i++)
	{
		if (i % 7 == wek1) {
			if (nowyear == n && nowmon == m && nowday == o) {
				printf(WHITE);
				printf("\t%d", o++);
				printf(BLUE);
			}
			else {
				printf("\t%d", o++);
			}
			wek1 = (wek1 + 1) % 7;
			if (wek1 == 1)
				printf("\n");
			day--;
		}
		else {
			printf(RED);
			printf("\t%d",day1++);
			printf(BLUE);
		}
	}
}
int year2020[monthnum];
int day2020[monthnum];
int main() {
	printf("输入年和月,输入w或s进行翻页");
	int n, m;
	scanf("%d%d", &n, &m);
	printf(BLUE);
	put(n,m);
	valueout(n, m);
	put(n,m);
	printf(NONE);
	while (1)
	{
		char t = getch();
		if (t=='s') {
			printf(BLUE);
			if (--m==0) {
				m = 12;
				n--;
			}
			put(n,m);
			valueout(n, m);
			put(n,m);
			printf(NONE);
		}
		else if(t=='w')
		{
			printf(BLUE);
			if (++m == 13) {
				m = 1;
				n++;
			}
			put(n,m);
			valueout(n, m);
			put(n,m);
			printf(NONE);
		}
	}
}

功能:
C语言项目:输出日历_第1张图片

你可能感兴趣的:(c语言,算法,开发语言)