代码拉取完成,页面将自动刷新
#include<stdio.h>
int main()
{
int month,year,days,weak;
printf("Please input year:\n");
scanf("%d",&year);
printf("Please input month:\n");
scanf("%d",&month);
days=CheckMonth(month,year);
weak=CheckWeak(month,year);
printf("\n");
CalendarPrinter(weak,days);
return 0;
}
int CalendarPrinter(int a,int b)//给出1号是星期几和当前月的天数
{
int times=0,day=1,weak=1,x=1;
if(b!=28)
if(a==6&&b==30)
times=5;
else
times=6;
else if(a!=1)
times=5;
else
times=4;
//printf("%d",times);
//确定有多少周
printf(" Mon Tue Wed Thu Fri Sat Sun\n");
for(weak=1;weak<=times;weak++)
{
for(x=1;x<=7;x++)
{
if(weak==1&&x<a)
printf(" ");
else
{
printf("%4d",day);
if(day==b)
return 0;
day++;
}
}
printf("\n");
}
return 0;
}
int CheckLeap(int year)//输入年份,闰年返回1,平年返回0
{
if(year%4==0&&year%100!=0||year%400==0)
return 1;
else
return 0;
}
int CheckMonth(int month,int year)//输入月份和年份,返回当月天数,失败返回0
{
int day;
switch(month){
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:{
if(CheckLeap(year)==1)
day=29;
else
day=28;
break;
}
default:day=0;break;//返回错误代码:0
}
return day;
}
int CheckWeak(int month,int year)//输入月份和年份,返回当月1日是星期几
{
int k=0,a,b,h=0;
if(year%100!=0&&year%4==0||year%400==0)
{
switch(month)//闰年
{
case 12:k=k+30;
case 11:k=k+31;
case 10:k=k+30;
case 9:k=k+31;
case 8:k=k+31;
case 7:k=k+30;
case 6:k=k+31;
case 5:k=k+30;
case 4:k=k+31;
case 3:k=k+29;
case 2:k=k+31;
}
}
else
{
switch(month)//平年
{
case 12:k=k+30;
case 11:k=k+31;
case 10:k=k+30;
case 9:k=k+31;
case 8:k=k+31;
case 7:k=k+30;
case 6:k=k+31;
case 5:k=k+30;
case 4:k=k+31;
case 3:k=k+29;
case 2:k=k+31;
}
}
a=k+1;
for(b=1900;b<year;b++)
{
if(b%100!=0&&b%4==0||b%400==0)//闰年
h=h+366;
else//平年
h=h+365;
}
if((a+h-1)%7==0)
return 7;
else
return (a+h-1)%7;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。