输入年月,输出日历 这个程序怎么写
不要什么太复杂的函数什么的
int n = 0, y = 0, r = 1, z = r, nn = n, yy = y; cin >> n >> y; nn = n; yy = y; while (nn >= 2018)if (--yy)z += 返回月的天数(nn, yy); else --nn, yy = 13; cout << (z %= 7) << endl; nn = 返回月的天数(n, y); yy = 0; while (r <= nn)if (yy > z) cout << r++ << ((yy++ % 7) ? "\t" : "\t\n"); else cout << (r > 1?to_string(r++):".") << ((yy++ % 7) ? "\t" : "\t\n");
[此贴子已经被作者于2020-1-10 14:32编辑过]
int n = 0, y = 0, r = 1, z = r, nn = n, yy = y; cin >> n >> y; nn = n; yy = y; while (nn >= 2018)if (--yy)z += 返回月的天数(nn, yy); else --nn, yy = 13; cout << (z %= 7) << endl; nn = 返回月的天数(n, y); yy = 1; cout << "星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六\n.\t"; while (r <= nn)if (yy >= z) cout << r++ << ((++yy % 7) ? "\t" : "\t\n"); else cout << (r > 1?to_string(r++):".") << ((++yy % 7) ? "\t" : "\t\n");
[此贴子已经被作者于2020-1-10 14:50编辑过]
CTime time(CTime::GetCurrentTime()); SYSTEMTIME timeDest; time.GetAsSystemTime(timeDest); 输出万年历(timeDest.wYear, timeDest.wMonth, timeDest.wDay);
[此贴子已经被作者于2020-1-10 15:53编辑过]
#include <stdio.h> int isly(int year) { return ((!(year%4))&&(year%100)||(!(year%400))); } int mtod(int m) { int n=0; switch(m) { case 1:n=31;break; case 2:n=59;break; case 3:n=90;break; case 4:n=120;break; case 5:n=151;break; case 6:n=181;break; case 7:n=212;break; case 8:n=243;break; case 9:n=273;break; case 10:n=304;break; case 11:n=334;break; default:n=0; } return n; } int dmax(int y,int m) { if(m==2) { return 28+(isly(y)); } if((m==1||m==3||m==5||m==7||m==8||m==10||m==12)) return 31; return 30; } int day(int y,int m) { int lyn=0; int dn=0; int weekday; static int aday[7]={2,3,4,5,6,0,1}; if(y>=1901) { for(int i=1901;i<=y;i++) { lyn+=isly(i); } if(isly(y)) { if(m<=2) lyn--; } dn=(y-1901)*365+mtod(m-1)+lyn; weekday=aday[dn%7]; } if(y<1901) { for(int i=y;i<1901;i++) { lyn+=isly(i); } if(isly(y)) { if(m>2) lyn--; } dn=(1901-y)*365-mtod(m-1)+lyn; weekday=aday[dn%7]; } return weekday; } void printdate(int y,int m,int wd) { int cd=dmax(y,m); int mdate[40]={0}; printf(" 日 一 二 三 四 五 六\n"); for(int i=0;i<cd;i++) { mdate[i+wd]=i+1; } for(int i=0;i<cd+wd;i++) { if(mdate[i]==0) printf(" "); else printf("%3d",mdate[i]); if((i+1)%7==0) printf("\n"); } printf("\n"); } int main() { int y,m; printf("输入年月:"); do { scanf("%d%d",&y,&m); if(m<13&&m>0) { printf("\n"); printdate(y,m,day(y,m)); break; } else printf("输入不合法,请重新输入:"); } while(1); return 0; }
[此贴子已经被作者于2020-1-10 17:06编辑过]