| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 639 人关注过本帖
标题:[求助]计算任何一天是星期几?
只看楼主 加入收藏
hyxw5890
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2007-3-19
收藏
 问题点数:0 回复次数:6 
[求助]计算任何一天是星期几?
     RT谁帮忙说一下,多谢啦!!
2007-03-29 22:49
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
首先要给出某一天的星期,然后再以此作为开始来计算天数.

倚天照海花无数,流水高山心自知。
2007-03-29 23:02
福尔摩斯
Rank: 5Rank: 5
等 级:贵宾
威 望:12
帖 子:4011
专家分:370
注 册:2006-8-15
收藏
得分:0 
以下是引用nuciewth在2007-3-29 23:02:52的发言:
首先要给出某一天的星期,然后再以此作为开始来计算天数.

我记得有一个数学公式

我去查查


自我放逐。。。
2007-03-29 23:04
Saintseiya
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-3-29
收藏
得分:0 

在VC下运行

#include <iostream.h>
void main()
{int days=0,year,month,day,n,week,i;
int mont[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
cout<<"Input a date:"<<endl;
cout<<"year:";
cin>>year;
cout<<"month:";
cin>>month;
cout<<"day:";
cin>>day;
if(year%400==0||(year%4==0&&year%100!=0))
mont[2]=29;
for(i=1;i<month;i++)
days+=mont[i];
days+=day;
n=year-1+(year-1)/4-(year-1)/100+(year-1)/400+days;
week=n%7;
cout<<"This date is:";
switch (week)
{case 0: cout<<"Sunday.";break;
case 1: cout<<"Monday.";break;
case 2: cout<<"Tuesday.";break;
case 3: cout<<"Wendesday.";break;
case 4: cout<<"Thursday.";break;
case 5: cout<<"Friday.";break;
case 6: cout<<"Saturday.";break;
}
cout<<endl;
}

2007-03-29 23:24
mp3aaa
Rank: 5Rank: 5
等 级:贵宾
威 望:17
帖 子:2013
专家分:8
注 册:2006-2-15
收藏
得分:0 

俺自己写的万年历 那出来给你看上一眼
#include"stdio.h"
void weekday();
int leap(int);
int _2000yera(int x)
{
int sum=0;
int i;
if(x>=2000){
for(i=2000;i<x;i++)
{
sum+=(i%4==0&&i%100==0||i%400==0)?366:365;
}
return (sum+6)%7;
}
else{
for(i=x;i<2000;i++)
{
sum+=(i%4==0&&i%100==0||i%400==0)?366:365;
}
return (-sum%7+6)%7;
}

}
void weekday()
{
int i;
for(i=1;i<=7;i++)
printf("星期%d\t",i);
printf("\n");
}
int sp(int x)
{
int i;
for(i=1;i<=_2000yera(x);i++)
printf("\t");
return i;
}
int month(int ch,int x)
{
switch(ch)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:return 31;
case 4:
case 6:
case 9:
case 11:return 30;
case 2:return leap(x);
}
}
int leap(int x)
{
int b;
b=(x%4==0&&x%100!=0)||x%400==0?29:28;
return b;
}
int printyear(int x)
{
int mon,i=1,j,day;
printf("*********1月*********");
printf("\n");
weekday();
printf("\n");
i=sp(x);
for(day=1,mon=1;mon<=12;mon++)
{
for(j=1;j<=month(mon,x);j++,i++,day++)
{
printf("%d\t",j);
if(i%7==0){printf("\n");day=1;}
}
if(mon<12){
printf("\n");
printf("*********%d月*********\n",mon+1);
weekday();
printf("\n");
i=1;
i+=day-2;
for(;day-2>0;day--)
printf(" \t");}
}
}
main()
{
int x,exit;
printf("year:");
scanf("%d",&x);
printyear(x);
printf("\n输入任意数字结束:");
scanf("%d",&exit);

}


羊肉串 葡萄干 哈密瓜!!
2007-03-29 23:39
uuufff
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2006-12-11
收藏
得分:0 
顶楼上的,为什么没解释程序

无论学什么,总会有用上的一天!
2007-03-30 12:52
hawkeye
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2007-3-29
收藏
得分:0 
程序要自己慢慢看得

2007-03-31 22:14
快速回复:[求助]计算任何一天是星期几?
数据加载中...
 
   



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

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