| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 614 人关注过本帖
标题:请高手看一下错在哪里?
取消只看楼主 加入收藏
xiaowaibu
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-3-23
结帖率:100%
收藏
已结贴  问题点数:3 回复次数:1 
请高手看一下错在哪里?
输入年,月,日,;输出星期几
#include <stdio.h>
main()
{
    int y,m,d,w;
    scanf("%d%d%d",&y,&m,&d);
    if((y%4==0&&y%100!=0)||y%400==0)
    {
        switch(m)
        {
        case 1:w=(365*y+(y/4-y/100+y/400)+d-2)%7;break;
case 2:w=(365*y+(y/4-y/100+y/400)+d+29)%7;break;
case 3:w=(365*y+(y/4-y/100+y/400)+d+58)%7;break;
case 4:w=(365*y+(y/4-y/100+y/400)+d+89)%7;break;
case 5:w=(365*y+(y/4-y/100+y/400)+d+119)%7;break;
case 6:w=(365*y+(y/4-y/100+y/400)+d+150)%7;break;
case 7:w=(365*y+(y/4-y/100+y/400)+d+180)%7;break;
case 8:w=(365*y+(y/4-y/100+y/400)+d+211)%7;break;
case 9:w=(365*y+(y/4-y/100+y/400)+d+242)%7;break;
case 10:w=(365*y+(y/4-y/100+y/400)+d+272)%7;break;
case 11:w=(365*y+(y/4-y/100+y/400)+d+303)%7;break;
case 12:w=(365*y+(y/4-y/100+y/400)+d+333)%7;
        }
    }
        else
        {
        switch(m)
    {

    case 1:w=(365*y+(y/4-y/100+y/400)+d-1)%7;break;
    case 2:w=(365*y+(y/4-y/100+y/400)+d+30)%7;break;
    case 3:w=(365*y+(y/4-y/100+y/400)+d+58)%7;break;
    case 4:w=(365*y+(y/4-y/100+y/400)+d+89)%7;break;
    case 5:w=(365*y+(y/4-y/100+y/400)+d+119)%7;break;
    case 6:w=(365*y+(y/4-y/100+y/400)+d+150)%7;break;
    case 7:w=(365*y+(y/4-y/100+y/400)+d+180)%7;break;
    case 8:w=(365*y+(y/4-y/100+y/400)+d+211)%7;break;
    case 9:w=(365*y+(y/4-y/100+y/400)+d+242)%7;break;
    case 10:w=(365*y+(y/4-y/100+y/400)+d+272)%7;break;
    case 11:w=(365*y+(y/4-y/100+y/400)+d+303)%7;break;
    case 12:w=(365*y+(y/4-y/100+y/400)+d+333)%7;
    }
        }
    switch(w)
    {
    case 1:printf("1\n");break;
case 2:printf("2\n");break;
case 3:printf("3\n");break;
case 4:printf("4\n");break;
case 5:printf("5\n");break;
case 6:printf("6\n");break;
case 0:printf("7\n");
    }
}
搜索更多相关主题的帖子: 400 include 
2010-04-25 14:16
xiaowaibu
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-3-23
收藏
得分:0 
我知道错那了,谢谢
#include <stdio.h>
main()
{
    int y,m,d,w;
    scanf("%d%d%d",&y,&m,&d);
    if((y%4==0&&y%100!=0)||y%400==0)
        switch(m)
        {
        case 1:w=(365*(y-1)+((y-1)/4-(y-1)/100+(y-1)/400)+d)%7;break;
case 2:w=(365*(y-1)+((y-1)/4-(y-1)/100+(y-1)/400)+d+31)%7;break;
case 3:w=(365*(y-1)+((y-1)/4-(y-1)/100+(y-1)/400)+d+60)%7;break;
case 4:w=(365*(y-1)+((y-1)/4-(y-1)/100+(y-1)/400)+d+91)%7;break;
case 5:w=(365*(y-1)+((y-1)/4-(y-1)/100+(y-1)/400)+d+121)%7;break;
case 6:w=(365*(y-1)+((y-1)/4-(y-1)/100+(y-1)/400)+d+152)%7;break;
case 7:w=(365*(y-1)+((y-1)/4-(y-1)/100+(y-1)/400)+d+182)%7;break;
case 8:w=(365*(y-1)+((y-1)/4-(y-1)/100+(y-1)/400)+d+213)%7;break;
case 9:w=(365*(y-1)+((y-1)/4-(y-1)/100+(y-1)/400)+d+244)%7;break;
case 10:w=(365*(y-1)+((y-1)/4-(y-1)/100+(y-1)/400)+d+274)%7;break;
case 11:w=(365*(y-1)+((y-1)/4-(y-1)/100+(y-1)/400)+d+305)%7;break;
case 12:w=(365*(y-1)+((y-1)/4-(y-1)/100+(y-1)/400)+d+335)%7;
        }
        else
        switch(m)
    {

    case 1:w=(365*(y-1)+((y-1)/4-(y-1)/100+(y-1)/400)+d)%7;break;
    case 2:w=(365*(y-1)+((y-1)/4-(y-1)/100+(y-1)/400)+d+31)%7;break;
    case 3:w=(365*(y-1)+((y-1)/4-(y-1)/100+(y-1)/400)+d+59)%7;break;
    case 4:w=(365*(y-1)+((y-1)/4-(y-1)/100+(y-1)/400)+d+90)%7;break;
    case 5:w=(365*(y-1)+((y-1)/4-(y-1)/100+(y-1)/400)+d+120)%7;break;
    case 6:w=(365*(y-1)+((y-1)/4-(y-1)/100+(y-1)/400)+d+151)%7;break;
    case 7:w=(365*(y-1)+((y-1)/4-(y-1)/100+(y-1)/400)+d+181)%7;break;
    case 8:w=(365*(y-1)+((y-1)/4-(y-1)/100+(y-1)/400)+d+212)%7;break;
    case 9:w=(365*(y-1)+((y-1)/4-(y-1)/100+(y-1)/400)+d+243)%7;break;
    case 10:w=(365*(y-1)+((y-1)/4-(y-1)/100+(y-1)/400)+d+273)%7;break;
    case 11:w=(365*(y-1)+((y-1)/4-(y-1)/100+(y-1)/400)+d+304)%7;break;
    case 12:w=(365*(y-1)+((y-1)/4-(y-1)/100+(y-1)/400)+d+334)%7;
    }
    switch(w)
    {
    case 1:printf("1\n");break;
case 2:printf("2\n");break;
case 3:printf("3\n");break;
case 4:printf("4\n");break;
case 5:printf("5\n");break;
case 6:printf("6\n");break;
case 0:printf("7\n");
    }
}
2010-04-30 19:30
快速回复:请高手看一下错在哪里?
数据加载中...
 
   



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

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