C语言实现万年历

万年历

#include
int dp[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},
                {0,31,29,31,30,31,30,31,31,30,31,30,31}};
int getweekend(int y,int m,int d){
	if(m==1||m==2){
        m+=12;y--;
    }
    int w= (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400+1)%7;
    return w;
}
int chick(int year){
    return ((year%4==0&&year%100!=0)||year%400==0) ;
}
void show(int year,int month,int wd){
    int leep=chick(year);
    printf("    日    一    二    三    四    五    六\n");
    int f=0,cnt=0,i;
    while(cnt<dp[leep][month]){
    	for(i=0;i<7;i++){
	    	if(i<wd&&f==0){
	    		printf("      ");
			}
			else {
				f=1;
				if(cnt<dp[leep][month]){
					printf("%6d",++cnt);
				}
				else printf("      ");
			}
		}
		printf("\n");
	}
}
int main(){
	int leap;
	int year,month,wd;
	printf("请输入查询的年份和月份(中间用空格隔开)\n");
	scanf("%d %d",&year,&month);
	wd=getweekend(year,month,1);
	show(year,month,wd);
	return 0;
}

你可能感兴趣的:(模拟)