c万年历

一段以前写的老代码。
#include<stdio.h>												//万年历查询  2006-5-15
#include<stdlib.h>
#include <conio.h>

void PrintSpace(int SpaceNum)									//控制输出空格函数
{
for(int i=0;i<SpaceNum;i++)
	printf(" ");
}

void main()
{
int year;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int week;
int TempWeek;
char MonthName[12][10]={"January","February","March","April","May","June","July","August","September","October","November","December"};
char InputChar;

do
{
	printf("\n    ------------------------- \n");				//主界面
	printf("   |\t\t\t     |\n");
	printf("   |       My Calendar       |\n");
	printf("   |        2006-5-15        |\n");
	printf("   |\t\t\t     |\n");
	printf("    ------------------------- \n\n");

	do{															//循环接受输入
		printf(" Please enter a year:(format xxxx)");
		scanf("%d",&year);

		if(year>=0)
			{	
				TempWeek=year-1+(year-1)/4-(year-1)/100+(year-1)/400+1;
				break;
			}
		else
			printf(" Enter year error,please enter again!(year>=0)\n\n");	
	}
	while(1);

	system("cls");												//清屏

	printf("\n  ------------------------- \n");
	printf(" |\t\t\t   |\n");
	printf(" |       My Calendar       |\n");
	printf(" |        2006-5-15        |\n");
	printf(" |\t\t\t   |\n");
	printf("  ------------------------- \n");

	if((year%4==0&&year%100!=0)||(year%4==0&&year%400==0))		//如果输入为闰年则二月为29天
		day[1]++;

	printf("\n  Calendar of the year %d\n\n",year);

	for(int MonthCount=0;MonthCount<12;MonthCount++)			//大循环输出十二个月日历
	{
		if(MonthCount==0)										//确定当月第一天星期数
			week=TempWeek%7;
		else if(MonthCount==1)
			week=(TempWeek+day[0])%7;
		else if(MonthCount==2)
			week=(TempWeek+day[0]+day[1])%7;
		else if(MonthCount==3)
			week=(TempWeek+day[0]+day[1]+day[2])%7;
		else if(MonthCount==4)
			week=(TempWeek+day[0]+day[1]+day[2]+day[3])%7;
		else if(MonthCount==5)
			week=(TempWeek+day[0]+day[1]+day[2]+day[3]+day[4])%7;
		else if(MonthCount==6)
			week=(TempWeek+day[0]+day[1]+day[2]+day[3]+day[4]+day[5])%7;
		else if(MonthCount==7)
			week=(TempWeek+day[0]+day[1]+day[2]+day[3]+day[4]+day[5]+day[6])%7;
		else if(MonthCount==8)
			week=(TempWeek+day[0]+day[1]+day[2]+day[3]+day[4]+day[5]+day[6]+day[7])%7;
		else if(MonthCount==9)
			week=(TempWeek+day[0]+day[1]+day[2]+day[3]+day[4]+day[5]+day[6]+day[7]+day[8])%7;
		else if(MonthCount==10)
			week=(TempWeek+day[0]+day[1]+day[2]+day[3]+day[4]+day[5]+day[6]+day[7]+day[8]+day[9])%7;
		else
			week=(TempWeek+day[0]+day[1]+day[2]+day[3]+day[4]+day[5]+day[6]+day[7]+day[8]+day[9]+day[10])%7;

		printf("\t  %s %d\n",MonthName[MonthCount],MonthCount+1);
		printf(" Mon Tue Wed Thu Fri Sat Sun\n");
		printf("=============================\n");

		if(week==1)												//根据当月第一天星期数调用输出空格函数控制输出空格数
			PrintSpace(2);
		else if(week==2)
			PrintSpace(6);
		else if(week==3)
			PrintSpace(10);
		else if(week==4)
			PrintSpace(14);	
		else if(week==5)
			PrintSpace(18);
		else if(week==6)
			PrintSpace(22);
		else
			{
				PrintSpace(26);
				week=7;
			}

		for(int i=1,int count=week;i<=day[MonthCount];i++)		//输出当月日历,计数器当月第一天星期数初始化
			{
				if(count>7)								        //计数器为7时控制换行并重新归1
					{
						printf("\n");
						printf("  ");
						count=1;
					}
				if(i<10)
					printf("%d   ",i);					        //天数为1位数时输出3个空格
				else
					printf("%d  ",i);					        //天数为2位数时输出2个空格

				count++;
			}

		printf("\n\n");
	}

	day[1]=28;													//将本次输出年历的二月重新归为28天为下次年历输出做准备

	printf(" Continue print other year?(y/n)");					//询问用户继续或退出程序
	InputChar=getch();

	system("cls");

	if(InputChar=='n'||InputChar=='N')
		{
			printf("\n   ------------------------- \n");
			printf("  |\t\t\t    |\n");
			printf("  |       My Calendar       |\n");
			printf("  |        2006-5-15        |\n");
			printf("  |\t\t\t    |\n");
			printf("   ------------------------- \n\n");

			printf("     Program exit,bye bye!\n\n");
			exit(1);
		}
}while(1);

}

你可能感兴趣的:(C++,c,C#)