编写一万年历系统,这个程序有些看不懂,大神可不可以给我分析分析
从年函数和周函数开始就不懂,还有就是输出的那个空格不知道怎么出来的比如1号是周三,那前几个就是空起的
#include <windows.h>
#include <stdio.h>
#include <process.h>
int day_s();
int year_s();
int week_s();
void output_month();
int year,month;
int main()
{
SYSTEMTIME time;
GetSystemTime(&time);//获取当前系统的时间
year=time.wYear;
month=time.wMonth;
printf("\t\t今天是公元%d年%d月%d日\n\n",time.wYear,time.wMonth,time.wDay);
output_month();
return 0;
}
int day_s()
{
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:return 31;break;
case 4:
case 6:
case 9:
case 11:return 30;break;
case 2:
{
if(year%4==0&&year%100!=0||year%400==0) return 29;
else return 28;
break;
}
}
}
int year_s()
{
int s=1;
switch(month-1)
{
case 11:s+=30;
case 10:s+=31;
case 9:s+=30;
case 8:s+=31;
case 7:s+=31;
case 6:s+=30;
case 5:s+=31;
case 4:s+=30;
case 3:s+=31;
case 2:
{
if(year%4==0&&year%100!=0||year%400==0)s+=29;
else s+=28;
}
case 1:s+=31;
}
return s;
}
int week_s()
{
int s=1,n;
n=(year-1)%400;
for(int i=1;i<=n;i++)
{
if(year%4==0&&year%100!=0||year%400==0)
s+=2;
else s+=1;
}
s+=year_s();
s%=7;
return s;
}
void output_month()
{
int week,day,i;
printf("\t\t公元%d年\n",year);
printf("\t\t公元%d月\n",month);
printf("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六\n");
day=day_s();
week=week_s();
for(i=1;i<=week;i++)
{
printf(" \t");
}
for(i=1;i<=day;i++)
{
printf("%d",i);
if((i+week)%7==0) printf("\n");
else printf("\t");
}
for(int j=1;j<=42-week-i;j++)
{
printf("\t");
}
printf("\n\n");
}