VC++打印日历中某月第一天是星期几的问题 已知1900年1月1日为星期一

1个回答

  • #include

    #include

    #define sunday 0

    #define monday 1

    #define tuesday 2

    #define wednesday 3

    #define thurday 4

    #define friday 5

    #define saturday 6

    void giveinstructions(void);

    int getyearfromuser(void);

    int getmonthfromuser(void);

    int monthdays(int month, int year);

    int firstdayofmonth(int month, int year);

    bool isleapyear(int year);

    void main(void)

    {

    int year,month,weekday;

    giveinstructions();

    year=getyearfromuser();

    month=getmonthfromuser();

    weekday=firstdayofmonth(month,year);

    printf("%d",weekday);

    getchar();

    }

    void giveinstructions(void)

    {

    printf("This program displays a calendar for a fulln");

    printf("year. The year must not be before 1900.n");

    }

    int getyearfromuser(void)

    {

    int year;

    while(1)

    {

    printf("Which year?n");

    scanf("%ld",&year);

    getchar();

    if(year>=1900)

    return(year);

    printf("The year must be at least 1900.n");

    }

    }

    int getmonthfromuser(void)

    {

    int month;

    while(1)

    {

    printf("Which month?n");

    scanf("%d",&month);

    getchar();

    return month;

    }

    }

    int monthdays(int month,int year)

    {

    switch(month)

    {

    case 1:

    return 0;

    case 2: if(isleapyear(year))

    return (29);

    else

    return (28);

    case 4:

    case 6:

    case 9:

    case 11:

    return(30);

    default :

    return(31);

    }

    }

    int firstdayofmonth(int month, int year)

    {

    int weekday,i;

    weekday=monday;

    for(i=1900;i