| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 739 人关注过本帖
标题:万年历问题:2月份总是28天
取消只看楼主 加入收藏
klpk521
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2011-11-28
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:1 
万年历问题:2月份总是28天

#include <stdio.h>
#include <stdlib.h>

#define Sun        0
#define Mon        1
#define Tue        2
#define Wed        3
#define Thur      4
#define Fri        5
#define Sat     6

char month[12][4]={"Jan","Feb","Mar","Apl","May","Jun","July","Aug","Sept","Oct","Nov","Dec"};


void GiveInstructions()  /*prints out instructions to the user*/
{
    printf("This program displays a calendar for a full\nyear.  the year must not before 1900.\nWhich year?");
}

int GetYearFromUser() /*reads in a year from the user*/
{
    int year;
    loop:
    scanf("%d",&year);
    if (year<1900)
    {
        printf("the year must be at least 1900.\nWhich year?");
        goto loop;
    }
    return year;
}

int IsLeapYear(int year)  /*decide if the year input is leap year or not*/
{
    if(year%4==0&&year%100==0||year%400==0)
    return 1;
    else
    return 0;
}

int weekday(int year)  /*work out the weekday*/
{
    int day;
    day=(year+(year-1)/4-(year-1)/100+(year-1)/400)%7;
    return (day);
}

int MonthDay(int i)  /*get the days of all months*/
{
    int year;
    switch (i)
    {case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:return 31;break;
    case 4:
    case 6:
    case 9:
    case 11:return 30;break;
    case 2:
    if(IsLeapYear(year)==1)
    return 29;
    else if(IsLeapYear(year)==0)
    return 28;
    break;}
    return 0;
}

int PrintCalendar(int year)  /*printf the calendar*/
{
    int i,j,k,firstDay;
    firstDay=weekday(year);
    for (i=0;i<=11;i++)
    {
        printf("\t\t%s\n",month[i]);
        printf("Sun  Mon  Tue  Wed  Thu  Fri  Sat\n");
        for(j=0;j<firstDay;j++)
        {
            printf("     ");  /*make the first day align at week*/
        }
        for (k=1;k<=MonthDay(i+1);k++)
        {
            if(k<10)
            printf("%d    ",k);
            else
            printf("%d   ",k);
            if((k+j)%7==0)
            printf("\n");   
        }
        if((MonthDay(i+1)%7+firstDay)%7==0)  /*define the first day for next loop*/
        firstDay=0;
        else
        {firstDay=MonthDay(i+1)%7+firstDay;
        if(firstDay>7)
        firstDay=firstDay-7;
        printf("\n\n");}
    }
    return 0;
}

int main()
{
int year;

GiveInstructions();  /*prints out instructions to the user*/
year = GetYearFromUser(); /*reads in a year from the user*/
PrintCalendar(year); /* prints a calendar for an entire year*/
return 0;
}
            
请高手赐教
搜索更多相关主题的帖子: calendar 万年历 displays include 
2011-11-28 20:53
klpk521
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2011-11-28
收藏
得分:0 
回复 2楼 yuccn
thanX

[ 本帖最后由 klpk521 于 2011-11-30 00:14 编辑 ]
2011-11-30 00:13
快速回复:万年历问题:2月份总是28天
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023924 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved