#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <time.h>
int main(void)
{
void title(int,int);
int WEEK(int,int);
void nianli(int,int,int);
int year,month;
int i,j;
printf("\n\n");
printf("\t######################################################\n");
printf("\t###### 年历显示 #####\n");
printf("\t######################################################\n");
printf("\t######################################################\n");
printf("\t###### #####\n");
printf("\t###### 1.查询年历 #####\n");
printf("\t###### 2.查询日历 #####\n");
printf("\t###### 3.查询具体日期和假期 #####\n");
printf("\t###### 0.退出程序 #####\n");
printf("\t######################################################\n");
printf("\t######################################################\n");
printf("\n\n");
printf("\t\t\t您的选择是:");
scanf("%d",&j);
switch(j)
{
case 1:printf("\t请输入要查询的年份(如2013):");
scanf("%d",&year);
for(month=1;month<13;month++)
{
title(year,month);
i=WEEK(year,month);
nianli(i,month,year);
printf("\n\n\n");
}
break;
case 2:printf("\t请输入要查询的年月(如2013-02):");
scanf("%d-%d",&year,&month);
printf("\n\n");
if(month<1&&month>12)
{
printf("\t请输入正确的月份。\n");
break;
}
title(year,month);
i=WEEK(year,month);
nianli(i,month,year);
printf("\n\n\n");
getchar();
break;
case 3:
case 0:exit(0);
default:printf("\n\t请输入正确的序号\n");
}
return 0;
}
void title (int year,int month)
{
printf("\n");
printf(" *******************************************************\n ");
printf(" %d年 %d月 \n",year,month);
printf(" *******************************************************\n ");
printf("\t星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六\n ");
}
void nianli(int i,int month,int year)
{
const int mon[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int a[32],m,j;
int leap(int year);
static int x=1;
for(j=0;j<32;j++)
a[j]=j;
if(i>0)
{
for(;x<=i;x++) printf(" ");
}
if(leap(year)==1)
{
if(month==2)
{
for(m=1;m<=mon[2]+1;m++)
{
printf("\t%d",a[m]);
if(x%7==0) printf("\n");
x++;
}
printf("\n");
}
else
for(m=1;m<=mon[month];m++)
{
printf("\t%d",a[m]);
if(x%7==0) printf("\n");
x++;
}
printf("\n");
}
else
for(m=1;m<=mon[month];m++)
{
printf("\t%d",a[m]);
if(x%7==0) printf("\n");
x++;
}
printf("\n");
}
int leap(year)
{
if((year%4==0&&year%100!=0)||(year%400==0))
return 1;
else
return 0;
}
//******************************************************************
int WEEK(int year,int month)
{
int week,c,y,i;
if(month==1||month==2){month+=12;year-=1;}
c=year/100;
y=year-c*100;
week=(int)(c/4)-2*c+y+(int)(y/4)+(int)(13*(month+1)/5);
while(week<0)
{
week+=7;
}
week%=7;
switch (week)
{
case 1: i=1; break;
case 2: i=2; break;
case 3: i=3; break;
case 4: i=4; break;
case 5: i=5; break;
case 6: i=6; break;
case 0: i=0; break;
}
return i;
}
这么就对齐了 但是 你看看吧
#include <conio.h>
#include <string.h>
#include <time.h>
int main(void)
{
void title(int,int);
int WEEK(int,int);
void nianli(int,int,int);
int year,month;
int i,j;
printf("\n\n");
printf("\t######################################################\n");
printf("\t###### 年历显示 #####\n");
printf("\t######################################################\n");
printf("\t######################################################\n");
printf("\t###### #####\n");
printf("\t###### 1.查询年历 #####\n");
printf("\t###### 2.查询日历 #####\n");
printf("\t###### 3.查询具体日期和假期 #####\n");
printf("\t###### 0.退出程序 #####\n");
printf("\t######################################################\n");
printf("\t######################################################\n");
printf("\n\n");
printf("\t\t\t您的选择是:");
scanf("%d",&j);
switch(j)
{
case 1:printf("\t请输入要查询的年份(如2013):");
scanf("%d",&year);
for(month=1;month<13;month++)
{
title(year,month);
i=WEEK(year,month);
nianli(i,month,year);
printf("\n\n\n");
}
break;
case 2:printf("\t请输入要查询的年月(如2013-02):");
scanf("%d-%d",&year,&month);
printf("\n\n");
if(month<1&&month>12)
{
printf("\t请输入正确的月份。\n");
break;
}
title(year,month);
i=WEEK(year,month);
nianli(i,month,year);
printf("\n\n\n");
getchar();
break;
case 3:
case 0:exit(0);
default:printf("\n\t请输入正确的序号\n");
}
return 0;
}
void title (int year,int month)
{
printf("\n");
printf(" *******************************************************\n ");
printf(" %d年 %d月 \n",year,month);
printf(" *******************************************************\n ");
printf("\t星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六\n ");
}
void nianli(int i,int month,int year)
{
const int mon[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int a[32],m,j;
int leap(int year);
static int x=1;
for(j=0;j<32;j++)
a[j]=j;
if(i>0)
{
for(;x<=i;x++) printf(" ");
}
if(leap(year)==1)
{
if(month==2)
{
for(m=1;m<=mon[2]+1;m++)
{
printf("\t%d",a[m]);
if(x%7==0) printf("\n");
x++;
}
printf("\n");
}
else
for(m=1;m<=mon[month];m++)
{
printf("\t%d",a[m]);
if(x%7==0) printf("\n");
x++;
}
printf("\n");
}
else
for(m=1;m<=mon[month];m++)
{
printf("\t%d",a[m]);
if(x%7==0) printf("\n");
x++;
}
printf("\n");
}
int leap(year)
{
if((year%4==0&&year%100!=0)||(year%400==0))
return 1;
else
return 0;
}
//******************************************************************
int WEEK(int year,int month)
{
int week,c,y,i;
if(month==1||month==2){month+=12;year-=1;}
c=year/100;
y=year-c*100;
week=(int)(c/4)-2*c+y+(int)(y/4)+(int)(13*(month+1)/5);
while(week<0)
{
week+=7;
}
week%=7;
switch (week)
{
case 1: i=1; break;
case 2: i=2; break;
case 3: i=3; break;
case 4: i=4; break;
case 5: i=5; break;
case 6: i=6; break;
case 0: i=0; break;
}
return i;
}
这么就对齐了 但是 你看看吧