今天参考网上各路大神代码,然后自己利用思路打了一遍

#include<stdio.h>

#define

int runnian_day(int,int,int);
int is_runnian(int);
int get_days(int, int, int); //返回从公元元年算起,某年某月某日是第几天, 用这个数字算星期几
int days_of_year(int, int, int); //返回某年某月某日是当前年份第几天
int days_of_month(int, int); //返还某年某月有几天
void whichday(int,int,int);
void print_last(int,int,int);

int main(){
int i,j,k;
printf("请输入年月日(格式为2000/2/22):");
scanf("%d/%d/%d",&i,&j,&k);
print_last(i,j,k);
}

int runnian_day(int a,int b,int c){
int sum = 0;
int i;
for(i=1;i<=a-1;i++){
if(is_runnian(i)){
sum ++;
}
}
return sum;

}

int is_runnian(int a){
if((a%4 == 0&&a%100 != 0)||(a%400 == 0)){
return 1;
}else{
return 0;
}
}

//返回这一天从公元元年算起是第几天,算法:1.先算整年的部分:比如2018年,完整已经过了的年份有2017个,按平年算有 2017 * 365 天,但是其中闰年是366天,每个闰年少算了一天。1至2017有几个闰年呢
int get_days(int year, int month, int day)
{
int days = days_of_year(year, month, day);
int temp = year-1;
return temp * 365 + runnian_day(year,month,day) + days;
}



//返回这一天在当年是第几天
int days_of_year(int year, int month, int day)
{
int i;
int days = 0;
for(i = 1; i < month; i++)
{
days += days_of_month(year, i);

}
return days + day;
}

//返回这个月一共有多少天
int days_of_month(int year, int month)
{
//存储平年每月的天数
const int month_days[MONTHS] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if(month ==2 && is_runnian(year))
return 29; // 如果是闰年2月,返回29天
else
return month_days[month-1]; //正常返回
}

void whichday(int a,int b,int c){
int temp = get_days(a,b,c)%7;
printf(" 今天是星期");
switch(temp){
case 0:puts("日");break;
case 1:puts("一");break;
case 2:puts("二");break;
case 3:puts("三");break;
case 4:puts("四");break;
case 5:puts("五");break;
case 6:puts("六");break;
}
puts("");puts("");puts("");puts("");puts("");
system("pause");
}

void print_last(int a,int b,int c){
int firstday_of_tmonth = get_days(a, b, 1) % 7;
int tmonth_days = days_of_month(a, b); //这个月一共多少天
int i,j;
puts("");puts("");puts("");
printf(" ");
switch(b)
{
case 1: printf("January\n"); break;
case 2: printf("February\n"); break;
case 3: printf("March\n"); break;
case 4: printf("April\n"); break;
case 5: printf("May\n"); break;
case 6: printf("June\n"); break;
case 7: printf("July\n"); break;
case 8: printf("August\n"); break;
case 9: printf("September\n"); break;
case 10: printf("October\n"); break;
case 11: printf("November\n"); break;
case 12: printf("December\n"); break;
default: printf("Bad input of month, please enter a right month.\n"); return;
}
puts(" Mon Tues Wed Thur Fri Sat Sun");

for(i=1;i<=tmonth_days;i++){
if(i==1){
//先打印第一天的位置
for(j = 1; j < firstday_of_tmonth; j++) {
printf(" ");
}
printf("%6d", 1);
//如果今天是星期日,换行
if(firstday_of_tmonth == 7)
printf("\n");
continue;
}
printf("%6d", i);
if(((firstday_of_tmonth+i-1)%7 == 0)||(i==tmonth_days)){
puts("");
}
}
whichday(a,b,c);
}