C语言写万年历,我实在写不出来了

适用于从公元1年1月1日到公元10000年之间所有日期的显示。
1.提供系统操作的主界面;
2.查询某年某月某日(阳历)是星期几;
3.判断某年是否是闰年;
4.查询某月的最大天数;
5.打印某年的全年日历或某年某月的月历。
用visual系统编写
回答的好了可以追加酬劳的
实在是写不出来了各位教教我怎么写吧!!


#include<stdio.h>
#include<stdlib.h>
int main()
{    
    int i,j,h,k,r,m,n,s,year,mon[12]={31,28,31,30,31,30,31,31,30,31,30,31},day[12];
    printf("请输入年份:");
    scanf("%d",&year);
    printf("想要排几行:");
    scanf("%d",&n);
    if(year%4==0&&year%100!=0||year%400==0)
        mon[1]=29;
    day[0]=(year+(year-1)/4-(year-1)/100+(year-1)/400)%7;
    for (m=1;m<12;m++)
        day[m]=(day[m-1]+mon[m-1])%7;
    for (i=1;i<=n;i++)
    {
        printf("_____________________   ");
    }
    printf("\n");
    for(i=1;i<=12/n+1;i++)
    {
        for(j=1;j<=10;j++)
        {
            for (r=1,s=(i-1)*n;r<=n&&s<12;r++,s++)
            {
                if (j==1)
                    printf("%8d年%3d月      ",year,s+1);
                if (j==2||j==10)
                    printf("_____________________");
                if (j==3)
                    printf(" 日 一 二 三 四 五 六");
                for (k=(j-4)*7+1,h=1;k<=42&&h<=7;k++,h++)
                {
                    if (k<=mon[s]+day[s])
                    {
                        if (j==4)
                        {
                            if (k<=day[s])
                                printf("   ");
                            else
                                printf("%3d",k-day[s]);
                        }
                        else if (j!=1&&j!=2&&j!=3&&j!=10)
                            printf("%3d",k-day[s]);
                    }
                    else
                        printf("   ");
                }
                printf("   ");
            }
            printf("\n");    
        }
    }
    system("color B0");
    system("pause");
    return 0;
}

显示某年全年日历的运行结果(其它要求的功能都有,可以看截图中的菜单):

img

代码:

#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>

//没有考虑1582年10月缺失的10天
// 判断闰年
int isleapyear(int year)
{
    if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
        return 1;
    else
        return 0;
}
// 获取月份的天数
int daysofmonth(int year, int mon)
{
    int arr[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
    if (isleapyear(year))
        arr[2] = 29;
    return arr[mon];
}

//返回年的累加天数
int calMonth(int year, int month)
{
    int shift = 0;
    if (isleapyear(year))
        shift = 1;
    switch (month)
    {
    case 0:return 0;
    case 1:return 31;
    case 2:return 31 + 28 + shift;
    case 3:return 31 + 28 + 31 + shift;
    case 4:return 31 + 28 + 31 + 30 + shift;
    case 5:return 31 + 28 + 31 + 30 + 31 + shift;
    case 6:return 31 + 28 + 31 + 30 + 31 + 30 + shift;
    case 7:return 31 + 28 + 31 + 30 + 31 + 30 + 31 + shift;
    case 8:return 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + shift;
    case 9:return 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + shift;
    case 10:return 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + shift;
    case 11:return 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + shift;
    case 12:return 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 + shift;
    default:return 0;
    }
}


// 判断某天是周几
int weekofday(int year, int mon, int day)
{
    // 1900-1-1 星期一 
    int days = 0;
    if (year < 1900)
    {
        //1.计算从year+1到1900年的天数
        for (int y = year + 1; y < 1900; y++)
        {
            if (isleapyear(y))
                days += 366;
            else
                days += 365;
        }
        //2.year年的天数
        if (isleapyear(year))
            days += 366 - calMonth(year, mon - 1) - day;
        else
            days += 365 - calMonth(year, mon - 1) - day;


        int wk = days % 7;
        return (7 - wk);
    }
    else
    {
        //1.计算从1900年到year的天数
        for (int y = 1900; y < year; y++)
        {
            if (isleapyear(y))
                days += 366;
            else
                days += 365;
        }
        //2.year年的天数
        days += calMonth(year, mon - 1) + day - 1;

        int wk = days % 7 + 1;
        return wk;

    }



}

void showwk(int wk)
{
    switch (wk)
    {
    case 1:
        printf("星期一\n"); break;
    case 2:
        printf("星期二\n"); break;
    case 3:
        printf("星期三\n"); break;
    case 4:
        printf("星期四\n"); break;
    case 5:
        printf("星期五\n"); break;
    case 6:
        printf("星期六\n"); break;
    case 7:
        printf("星期日\n"); break;
    }
}

//显示某年某月的日历
void showRl(int year, int mon)
{
    int day, wk, days;
    int i, j;
    const char* weeks[] = { " ","一","二","三","四","五","六","日" };//仿windows日历显示
    days = daysofmonth(year, mon);
    for (i = 1; i <= 7; i++)
        printf("%2s ", weeks[i]);
    printf("\n");
    for (day = 1; day <= days; day++)
    {
        wk = weekofday(year, mon, day);
        if (day == 1)
        {
            for(j=1;j<wk;j++)
                printf("   ");
        }
        if(wk != 7)
            printf("%2d ", day);
        else
            printf("%2d\n", day);
    }
    printf("\n\n");
}

//显示某年的日历
void showYear(int year)
{
    int i = 1;
    for (; i <= 12; i++)
    {
        printf("%d年%d月日历:\n",year,i);
        showRl(year, i);
    }
}

int main()
{
    int year, mon, day;
    int op;
    int wk;
    while (1)
    {
        system("cls");
        printf("***************************************\n");
        printf("                 万年历                \n");
        printf("1.查询某年某月某日星期几\n");
        printf("2.判断某年是否是闰年\n");
        printf("3.查询某月的最大天数\n");
        printf("4.打印某年的全年日历\n");
        printf("5.打印某年某月的日历\n");
        printf("0.退出程序\n");
        printf("***************************************\n");
        printf("请选择:");
        while (1) {
            scanf("%d", &op);
            if (op >= 0 && op <= 5)
                break;
            else
                printf("请输入0-5的值:");
        }
        system("cls");
        switch (op)
        {
        case 1:
            printf("请输入日期(如2020 2 2):");
            scanf("%d %d %d", &year, &mon, &day);
            wk = weekofday(year, mon, day);
            showwk(wk);
            break;
        case 2:
            printf("请输入年份:");
            scanf("%d", &year);
            if (isleapyear(year))
                printf("%d年是闰年\n", year);
            else
                printf("%d年不是闰年\n", year);
            break;
        case 3:
            printf("请输入年月:");
            scanf("%d %d", &year, &mon);
            printf("%d年%d月的最大天数是%d\n", year, mon, daysofmonth(year, mon));
            break;
        case 4:
            printf("请输入年:");
            scanf("%d", &year);
            showYear(year);
            break;
        case 5:
            printf("请输入年月:");
            scanf("%d %d", &year, &mon);
            printf("%d年%d月日历如下:\n",year,mon);
            printf("---------------------------------\n\n");
            showRl(year,mon);
            break;
        case 0:
            return 0;
        }
        system("pause");
    }


    return 0;
}



供参考:

#include <iostream>
#include <iomanip>
#include <string>
#include <windows.h>
using namespace std;
string week[7]={"星期一","星期二","星期三","星期四","星期五","星期六","星期日"};
int isLeap(int y) // 闰年判断函数
{
    if((y%4==0 && y%100!=0)||(y%400==0))
        return 1;
    else
        return 0;
}
int GetDaysOfMonth(int y, int m)//每月的天数
{
    int daysOfMonth[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
    if(isLeap(y) && m == 2)   return daysOfMonth[m-1]+1;
    return daysOfMonth[m-1];
}
int Get_Week(int y,int m,int d)//计算星期数(星期一 -- 星期日:0 -- 6)
{
    int week = -1;
    if(m==1 || m == 2){
       m += 12;  y--;
    }
    week=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;
    return week;
}
int GetDaysOfYear(int y,int m,int d)//某天是该年的第几天
{
    int i,days=0;
    for (i=1;i < m;i++)
         days += GetDaysOfMonth(y,i);
    days += d;
    return days;
}
void ShowCalendar(int year,int month,int day=1)//格式输出日历表
{
    int i,k,count=0;//每月天数
    int dayofweek=0;//星期几

    cout<<setw(12)<<" "<<year<<"年"<<month<<"月"<<endl;
    cout<<"--------------------------------------\r\n";
    cout<<"   日   一   二   三   四   五   六   \r\n";
    cout<<"--------------------------------------\r\n";

    dayofweek=(1+Get_Week(year,month,day))%7;//每月1日星期数
    count=GetDaysOfMonth(year,month);        //每月天数

    for(i=0;i<dayofweek;i++) cout<<setw(5)<<" ";//填充前面空格
    for(i=1,k=dayofweek;i<=count;i++,k++){
        cout<<setw(5)<<i;
        if((k+1)%7==0 && i!=count) cout<<endl;//满7天,换行
    }
    cout<<"\r\n--------------------------------------\r\n\r\n";
}
void menu() //菜单函数
{
    cout<<"\t\t\t\t\t----------------------------------"<<endl;
    cout<<"\t\t\t\t\t*                                *"<<endl;
    cout<<"\t\t\t\t\t*        欢迎使用本系统          *"<<endl;
    cout<<"\t\t\t\t\t*                                *"<<endl;
    cout<<"\t\t\t\t\t----------------------------------"<<endl;
    cout<<endl;
    cout<<endl;
    cout<<"\t\t\t本系统具有以下功能"<<endl;
    cout<<"\t\t\t\t\t1.打印某年的全年日历"<<endl;
    cout<<"\t\t\t\t\t2.打印某年某月的月历"<<endl;
    cout<<"\t\t\t\t\t3.查询某年某月某日是星期几"<<endl;
    cout<<"\t\t\t\t\t4.判断某年某月某日是本年度第几天"<<endl;
    cout<<"\t\t\t\t\t5.判断某年是否闰年"<<endl;
    cout<<"\t\t\t\t\t6.查询某年某月的最大天数"<<endl;
    cout<<"\t\t\t\t\t7.退出"<<endl;
    cout<<"\t\t\t请选择按键(1-7):";
}

int main()
{
    int  year=0,month=0,day=0,nChoise=1;
    while (nChoise){
          menu();
          cin>>nChoise;
          switch (nChoise)
          {
              case 1:
                    cout<<"输入年份:"; cin>>year;
                    for (month=1;month<=12;month++)
                         ShowCalendar(year,month,1);
                    break;
              case 2:
                    cout<<"输入年份:"; cin>>year;
                    cout<<"输入此年月份(1-12):"; cin>>month;
                    ShowCalendar(year,month,1);
                    break;
              case 3:
                    cout<<"输入年份:"; cin>>year;
                    cout<<endl<<"输入月份(1-12):"; cin>>month;
                    cout<<endl<<"输入此年此月相应的日期(1-28:29:30:31):"; cin>>day;
                    cout<<endl<<"该天是:"<<week[Get_Week(year,month,day)]<<endl;
                    break;
              case 4:
                    cout<<"输入年份:"; cin>>year;
                    cout<<endl<<"输入月份(1-12):"; cin>>month;
                    cout<<endl<<"输入此年此月相应的日期(1-28:29:30:31):"; cin>>day;
                    cout<<endl<<"该天是该年度第"<<GetDaysOfYear(year,month,day)<<"天。"<<endl;
                    break;
              case 5:
                    cout<<"输入年份:"; cin>>year;
                    if(isLeap(year)) cout<<"该年是闰年。"<<endl;
                    else             cout<<"该年非闰年。"<<endl;
                    break;
              case 6:
                    cout<<"输入年份:"; cin>>year;
                    cout<<"输入此年月份(1-12):"; cin>>month;
                    cout<<"该月最大天数:"<<GetDaysOfMonth(year, month)<<endl;
                    break;
              case 7:
                    nChoise = 0;
                    break;
             default:
                    nChoise = 1;
                    cout<<"无效的菜单项!"<<endl;
                    break;
        }
        system("pause");
        system("cls");
    }
    return 0;
}

进行到哪一步了

好大一个工程,可参https://blog.csdn.net/xianfajushi/article/details/103925143