| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1773 人关注过本帖
标题:一个超级简单的万年历程序,征求高手意见!
取消只看楼主 加入收藏
tinx
Rank: 2
等 级:论坛游民
帖 子:24
专家分:29
注 册:2008-10-19
结帖率:0
收藏
 问题点数:0 回复次数:0 
一个超级简单的万年历程序,征求高手意见!
#include <iostream.h>
#include <iomanip.h>
int week (int y, int m, int d) //日期换算星期   
{
    if (m==1||m==2)  y=y-1,m=m+12;
    return ((d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7);
}
bool leap(int y)  //判断闰年
{
    return ((y%4==0&&y%100!=0)||(y%400==0));
}

void main()
{
    int year,month,day,t,i;
    char c;
    bool leap(int y);
    int week(int y,int m,int d);
    N:cout<<"请输入正确的年份和月份(例如:2008 9):";
    cin>>year>>month;
    if(year<=0||month<=0||month>12) goto N;
    cout<<"\n                 "<<"公元"<<year<<"年"<<month<<"月\n";
    cout<<"  *****************************************  \n";
    if (month==4||month==6||month==8||month==9||month==11) day=30;
    else
        if(month==2)
            if(leap(year)==1) day=29;
            else day=28;
        else day=31;
    cout<<"    Mon   Tue   Wed   Thu   Fri   Sat   Sun"<<endl;   
    t=week(year,month,1)*6+4;
    if(t==40) cout<<"                                        "<<setw(2)<<"1"<<endl;
    else
    {
        for (i=1;i<=t;i++) cout<<" ";
        cout<<setw(2)<<"1";
    }
    for(i=2;i<=day;i++)
    {
        t=week(year,month,i);
        if(t==6) cout<<"    "<<setw(2)<<i<<endl;
        else cout<<"    "<<setw(2)<<i;
    }
    cout<<endl;
cout<<"  *****************************************  \n";
while(1)
{
    cout<<"\n重新输入(N)| 退出(Q):";
    cin>>c;
    if (c=='N') goto N;
    if (c=='Q') break;
}
}

[[it] 本帖最后由 tinx 于 2008-10-20 22:27 编辑 [/it]]
搜索更多相关主题的帖子: 万年历 意见 超级 
2008-10-19 15:39
快速回复:一个超级简单的万年历程序,征求高手意见!
数据加载中...
 
   



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

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