万年历

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void display(int x,int y,int m,int max)
{
	int s[6][7]={0};
	int  i = 0; j=0;
	s[0][m]= 1;
	for(j=m;j<7;j++)
		s[0][j]=(j-m)+s[0][m];
	s[1][0]=s[0][6]+1;
	for(i=2;i<6;i++)
		s[i][0]=s[1][0]+(i-1)*7;
	for(i=1;i<6;i++)
	{for(j=1;j<7;j++)
	s[i][j]=s[i][0]+j;

	  
	}
	printf("\t%d年 %d月\n",x,y);
	printf("_____________\n");
	printf("日 一 二 三 四 五 六\n");
	for(i=0;i<6;i++)
	{
		for(j=0;j<7;j++)
		{
			if(s[i][j]==0)
				printf(" ");
			if(s[i][j]!=0&&s[i][j]<=max)
				printf("%3d",s[i][j]);
			printf("\n");

		}
	}
	int Year(int year)
	{
		if(year%4==0&&year%100!=0||year%400==0)
			return 1;
		else return 0;
	}
	void main()
	{
		int max[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
		int year=2016;
		int month=2;
		int star[13]={1,1,3,1,1,3,1,1,3,1,1,3};
		int i=1;
		if(Year(year))max[2]++;
		for(i=1;i<=12;i++)
		{
			star[i]=(1+2*i+3*(i+1)/5+year+year/4-year/100+year/400)%7
				display(year,i,star[i],  max[i]);
		}
	}

#include<iostream>
#include"cale.h"
using namespace std;
bool isLeapYear(int year)
{
	if(year % 4 == 0 &&  year % 100!=0 || year % 400 == 0)
		return true;
	 else return false;
}
void PrintWeek(int weekday)
{
	switch(weekday)
	{
	case 0:cout<<"周日 ";break;
    case 1:cout<<"周一 ";break;
    case 2:cout<<"周二 ";break;
    case 3:cout<<"周三 ";break;
    case 4:cout<<"周四 ";break;
	case 5:cout<<"周五 ";break;
    case 6:cout<<"周六 ";break;

	}
}
void PrintMonth(int month)
{
	switch(month)
	{
	case 1 : cout<<"一 月";break;
    case 2 : cout<<"二 月";break;
    case 3 : cout<<"三 月";break;
    case 4 : cout<<"四 月";break;
    case 5 : cout<<"五 月";break;
    case 6 : cout<<"六 月";break;
	case 7 : cout<<"七 月";break;
    case 8 : cout<<"八 月";break;
    case 9 : cout<<"九 月";break;
    case 10 : cout<<"十 月";break;
    case 11 : cout<<"十一 月";break;
    case 12 : cout<<"十二 月";break;

	}
} 
int WeekDay(int year,int month,int year)
{
	int i,sum = 0;
	for(i = 1900;i<year;i++)
		if(isLeapYear(i))
			sum += 366;
		else
			sum += 365;
	for(i = 1;i<month;i++)
		sum += MonthDays(year,i);
	sum += day;
	return sum % 7;
}
int MonthDays(int year,int month)
{
	switch(month)
	{
	case 1:
    case 3:
	case 5:
    case 7:
	case 8:
    case 10:
	case 12:   return 31;
    case 4:
    case 6:
    case 9:
	case 11:     return 30;
    case 2:  if(isLeapYear(year))
				 return 29;
			 else
				 return 28;
defalut : cout<<"这是一个错误的月份! ";system("pause");
		return 0;
	}
}
void  PrintData(int year)
{
	struct EveryMon
	{
		int maxdata;
		int data;
	};
	struct EveryMon months[13];
	int i,j,k;
	int mon,week;
	for(i = 1;i<13;i++)
	{
		months[i].data = 1;
		months[i].maxdata = MonthDays(year,i);
	}
	for(i = 0;i<6;i++)
	{
		mon = 2*i+j;
		printf("%15s"," ");
		PrintMonth(mon);
		printf("%15s"," ");
		if(j == 1)
			printf("\t" );

	}
	printf("\n");
	for(j = 1;j<=2;j++)
	{
		PrintWeek(k);
	}
	if(j == 1)
		printf("\t");
}
    printf("\n");
	for(j = i;j<=2;j++)
	{
		mon = 2*i+j;
		week = WeekDay(year,mon,1);
		printf("% * d",week * 5 + 2,months[mon].data++);
		week++;
		while(week < 7)
		{
			printf("%2d",months[mon].data++)
				week++;
		}
		if(j == 1)
			printf("\t");

	}
	printf("\n");
	{
		for(j = 1;j <= 2;j++)
		{
			mon = 2*i+j;
			for(k = 0;k<7;k++)
			{
				if(months[mon].data<=months[mon].maxdata)
					printf("%2d",months[mon].data++)
				else
				printf("   ");
			}
			if(j == 1)
				printf("\t");

		}
		printf("\n");

	}
	printf("\n");

}
}
#include<iostream>
#include"cale.h"
using namespace std;
int main(void)
{
	int choice;
	int year,month,day,weekday;
	while(1)
	{
		cout<<"----------------------------------"<<endl;
		cout<<"请输入您的选择: ";
		cout<<"  1  求某个日期对应的星期"<<endl;
		cout<<"   2  输出某年的日历"<<endl;
		cout<<"    0   结束程序"<<endl;
		cout<<"----------------------------------------"<<endl;
		cin>>choice;
		switch(choice)
		{
		case 1 : cout<<"请输入年, 月,日:";
			cin>>year>>month>>day;
			cout<<year<<"年"<<month<<"月"<<day<<"日这天是";
			weekday = WeekDay(year,month,day);
			PrintWeek(weekday)
				break;
		case 2 : cout<<"请输入年份: ";
			cin>>year;
			PrintData(year);
			break;
		case 0:return 0;
		default: cout<<"输入错误,请重新输入"<<endl;
			break;
		}
		cout<<endl;
	}
}

bool isLeapYear(int year);
int WeekDay(int year,int month,int day);
int MonthDays(int year,int month);
void PrintWeek(int weekday);
void PrintMonth(int month);
void PrintData(int year);

 
 
 





 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值