| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 637 人关注过本帖
标题:怎样输出任意一天星期几
只看楼主 加入收藏
weizhong185321
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-11-23
收藏
 问题点数:0 回复次数:0 
怎样输出任意一天星期几
#include <iostream.h>
int isleap(int year);
int week1(int year,int month,int day,int i);
void outputweek(int week);
int year,month,day,i;
void main()
{
    
    cout<<"请输入年月日:";
    cin>>year>>month>>day;
     i=isleap(year);   
        static week=week1(year,month,day,i);
    
    outputweek(week);
}
int isleap(int year)
{
    if((year%4==0&&year%100!=0)||year%400==0)
    return 1;
    else  
    return 0;
}
int week1(int year,int month,int day,int i)
{
    if((month>=13||day>=32)||(i=0&&month==2&&day>=29))
    {
        cout<<"输入错误.";
        day=0;
    }
    switch(month)
    {
        case 2:if(day>=30)
        {
        cout<<"输入错误.";
        day=0;
        }
        else day+=31;
        break;
        case 3:if(day>=31)
        {
        cout<<"输入错误.";
        day=0;
        }
        else day+=31+29;
        break;
        case 4:if(day>=30)
        {
        cout<<"输入错误.";
        day=0;
        }
        else day+=31+29+31;
        break;
        case 5:if(day>=31)
        {
        cout<<"输入错误.";
        day=0;
        }
        else day+=31+29+31+30;
        break;
        case 6:if(day>=30)
        {
        cout<<"输入错误.";
        day=0;
        }
        else day+=31+29+31+30+31;
        break;
        case 7:if(day>=31)
        {
        cout<<"输入错误.";
        day=0;
        }
        else day+=31+29+31+30+31+30;
        break;
        case 8:if(day>=31)
        {
        cout<<"输入错误.";
        day=0;
        }
        else day+=31+29+31+30+31+30+31;
        break;
        case 9:if(day>=30)
        {
        cout<<"输入错误.";
        day=0;
        }
        else day+=31+29+31+30+31+30+31+31;
        break;
        case 10:if(day>=31)
        {
        cout<<"输入错误.";
        day=0;
        }
        else day+=31+29+31+30+31+30+31+31+30;
        break;
        case 11:if(day>=30)
        {
        cout<<"输入错误.";
        day=0;
        }
        else day+=31+29+31+30+31+30+31+31+30+31;
        break;
        case 12:if(day>=31)
        {
        cout<<"输入错误.";
        day=0;
        }
        else day+=31+29+31+30+31+30+31+31+30+31+30;
        break;
        default:break;
    }
    if(month>=3&&i==0)
                day-=1;
        int week;
        if(day!=0)  week=(year-1)+int((year-1)*0.1*10/4)-int((year-1)*0.1*10/100)+int((year-1)*0.1*10/400)+day;
        else week=0;
        return week;
        }
void outputweek(int week)
    {
         cout<<year<<"年"<<month<<"月"<<day<<"日是";
int w;
    if(week!=0&&day!=0) {
w=week%7;
switch(w)
{
    case 1:cout<<"星期一"<<endl;  break;    
    case 2:cout<<"星期二"<<endl;  break;
    case 3:cout<<"星期三"<<endl;  break;
    case 4:cout<<"星期四"<<endl;  break;
    case 5:cout<<"星期五"<<endl;  break;
    case 6:cout<<"星期六"<<endl;  break;
    case 0:cout<<"星期日"<<endl;  break;
    default:break;
    }
    }
    }






一不是闰年能有2月29天,有的输出错误后还显示星期几。哪错啦?
搜索更多相关主题的帖子: 万年历 
2008-11-23 16:30
快速回复:怎样输出任意一天星期几
数据加载中...
 
   



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

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