#include<stdio.h> #include<stdlib.h> int week(int year, int month); void print(int year, int month); void main() { int year,month; do { printf("enter year,month (EOF for exit): "); if(scanf("%d%d",&year,&month)==EOF) break; print(year,month); }while(1); system("pause"); } int week(int year, int month) { int centry,y,week; if ( month < 3 ) { year -= 1; month += 12; } centry=year/100; y=year-centry*100; week=(centry/4)-2*centry+(y+y/4)+(26*(month+1)/10); return (week%7+7)%7; } void print(int year, int month) { int i,n=week(year,month); int mon[12]={31,28,31,30,31,30,31,31,30,31,30,31}; if(year%400==0||year%4==0&&year%100!=0) mon[1]++; printf("Calenda: year-%d,month-%d ",year,month); printf("Sun Mon Tue Wed Thu Fri Sat "); for(i=0;i<n;i++) printf(" "); for(i=1;i<=mon[month-1];i++) { printf("%3d ",i); if((i+n)%7==0) printf(" "); } printf(" "); }