#include<stdio.h> int main(void) { int i,y,m,days,lp ,leap; printf("请输入年/月:"); scanf("%d/%d",&y,&m); leap=(y%4==0&&y%100!=0||y%400==0); for(i=1;i<m;i++){ switch(i){ case 1: case 3: case 5: case 7: case 8: case 10:case 12: days+=31;break; case 4: case 6: case 9: case 11: days+=30;break; case 2: days +=28+ leap;break; default: break; } } days += 1;//求y年m月1号是y年的第days天 int ye, week=1 ; for(ye=1990;ye<y;ye++){ lp=(ye%4==0&&ye%100!=0||ye%400==0); days+=365+lp; } //求输入的月份1号是从1990起第days天。 int wd,day; //当天周几; wd= days%7; printf("%d ",wd);//调试 printf(" %d 月 %d ",m,y); printf("日 一 二 三 四 五 六 "); switch(m){ case 1: case 3: case 5: case 7: case 8: case 10:case 12: day=31;break; case 4: case 6: case 9: case 11: day=30;break; case 2: day =28+ leap;break; default: break; } for(i=0;i<wd;i++) printf(" "); for(i = 1;i<=day;i++){ printf("%2d ",i); if((i+wd)%7==0) printf(" "); } printf(" "); return 0; }