调用万年历

include

void leapYear(int year)
{
if((year%4==0 && year%100!=0) || year%400==0)
{
printf("%d是闰年\n",year);
}
else
{
printf("%d不是闰年\n",year);
}
}
void Oftheweek(int year,int month)
{
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int i;
int sum=0;
if(year<1900||month<1||month>12)
{
printf("input error");
}
else
{
for(i=1900;i {
if((i%4==0 && i%100!=0) || i%400==0)
{
sum+=366;
}
else
{
sum+=365;
}
}
// printf("sum=%d\n",sum);
if((year%4==0 && year%100!=0) || year%400==0)
{
a[2]=29;
}
else
{
a[2]=28;
}
for(i=1;i {
sum+=a[i];
}
}
int week=sum%7;
week=(week+1)%7;
printf("%d年%d月的第一天是星期%d\n",year,month,week);
}
void calendar(int year,int month)
{
int i;
int sum=0;
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if(year<1900||month<1||month>12)
{
printf("input error");
}
else
{
for(i=1900;i {
if((i%4==0 && i%100!=0) || i%400==0)
{
sum+=366;
}
else
{
sum+=365;
}
}
// printf("sum=%d\n",sum);
if((year%4==0 && year%100!=0) || year%400==0)
{
a[2]=29;
}
else
{
a[2]=28;
}
for(i=1;i {
sum+=a[i];
}
}
int week=sum%7;
week=(week+1)%7;
// printf("week=%d\n",week);
printf("\t\t\t%d/%d\n",year,month);
printf("Sun\tMon\tTues\tWed\tThur\tFri\tSat\n");
int colum=0;
i=1;
for(colum=0;i<=week;colum++)
{
printf("\t");
i++;
}
for(i=1;i<=a[month];i++)
{
printf("%2d\t",i);
colum++;
if(colum%7==0)
{
printf("\n");
}
}
printf("\n");
}
int main()
{
int year;
printf("请输入想要查询的年份判断是否为闰年:");
scanf("%d",&year);
leapYear(year);
printf("请输入查询的年份和月份判断当月的第一天是星期几:");
int year1,month1;
scanf("%d%d",&year1,&month1);
Oftheweek(year1,month1);
printf("请输入查询的年份和月份查看日历:");
int year2,month2;
scanf("%d%d",&year2,&month2);
calendar(year2,month2);
return 0;
}

你可能感兴趣的:(调用万年历)