标题:测算星期的难点;
只看楼主
lordair
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-1-7
 问题点数:0 回复次数:3 
测算星期的难点;

小弟刚学语言,以下为小弟刚编的测算星期的程序--------输入日期即自动测试该日期是星期几?
请问:
1、为什么这个程序在集成环境实验5.1版本中可用,在龚辟愚的3.0版本及C-Free3.5 中却不可使用呢?还提示有出错信息?
2、相关老虾们是否有好的点子可以使它的命令更少些,及减少内存及CPU的处理命令?
3、另要什么样才能使它具备有输入日期即可测试其农历?
恳请赐教!!!!


main()
{
char c;
unsigned year,month,date,week,week1,sum,sum1,a[12],i,b[10000],t,t1,j,day,todye=2000,todmo=01,
today=01;
long n=0,n1;
printf("*******************************************************************************\n");
printf("********************* \001LIUFU's date&&week system program\003 ***********************\n");
printf("*******************************************************************************\n"); /**标题***/
printf("\n\n\n\nPlease entering date: Ge si: 0000-00-00\n");
loop:scanf("%d-%d-%d",&year,&month,&date);
if(year<2000||year>10000||month==0||month>12||date==0||date>31)
{ printf("\nYou enter error,please reenter:\n");goto loop;} /*若输入日期不正确,则提示*/

if(!((year%4==0&&year%100!=0)||year%400==0)) /*闰年及二月的天数*/
t=365;else t=366;
sum=(t==366&&month>2)?1:0;
for(j=todye;j<year-1;j++)b[j]=j;
for(j<year-1;j>=todye;j--)
{b[j]=j;
if((b[j]%4==0&&b[j]%100!=0)||b[j]%400==0)t1=366;else t1=365;
n=n+t1;}
n1=(year==todye)?n-366:n;
if(t1==365&&month==2&&date>28){printf("\n\n\nYou enter error,please reenter:\n");goto loop;}
if(t1==366&&month==2&&date>29){printf("\n\n\nYou enter error,please reenter:\n");goto loop;}

if(year>=todye&&month>todmo)
{ for(i=todmo;i<month-1;i++)a[i]=i;
for(i<month-1;i>=todmo;i--)
{a[i]=i;
switch(a[i])
{
case 0:day=0;break;case 1:day=31;break;case 2:day=28;break;case 3:day=31;break;case 4:day=30;
break;case 5:day=31;break;case 6:day=30;break;case 7:day=31;break;case 8:day=31;break;
case 9:day=30;break;case 10:day=31;break;case 11:day=30;break;case 12:day=31;break;}
sum=day+sum;}
week=(n1+sum+date-today)%7;
switch(week)
{case 0:printf("\n\n%d-%d-%d is Satarday\n",year,month,date);break;
case 1:printf("\n\n%d-%d-%d- is Sunday\n",year,month,date);break;
case 2:printf("\n\n%d-%d-%d is Moday\n",year,month,date);break;
case 3:printf("\n\n%d-%d-%d is Tuesday\n",year,month,date);break;
case 4:printf("\n\n%d-%d-%d is Wednsday\n",year,month,date);break;
case 5:printf("\n\n%d-%d-%d is Thursday\n",year,month,date);break;
case 6:printf("\n\n%d-%d-%d is Friday\n",year,month,date);break;}
}

else if(date-today>7)
week1=(date-today)%7;else week1=date-today;
switch(week1)
{case 0:printf("\n\n%d-%d-%d is Satarday\n",year,month,date);break;
case 1:printf("\n\n%d-%d-%d- is Sunday\n",year,month,date);break;
case 2:printf("\n\n%d-%d-%d is Moday\n",year,month,date);break;
case 3:printf("\n\n%d-%d-%d is Tuesday\n",year,month,date);break;
case 4:printf("\n\n%d-%d-%d is Wednsday\n",year,month,date);break;
case 5:printf("\n\n%d-%d-%d is Thursday\n",year,month,date);break;
case 6:printf("\n\n%d-%d-%d is Friday\n",year,month,date);break;}
printf("Begain enter 'y'or'Y',Exit enter 'Esc'\n");
c=getch();
while(c==121||c==89)
{ putch(c);putch('\n');goto loop;
if(c!=(121&&89))
break;}
}

[此贴子已经被作者于2006-3-17 13:12:02编辑过]

搜索更多相关主题的帖子: 难点 内存 week CPU 环境 
2006-03-16 11:44
feng1256
Rank: 4
等 级:贵宾
威 望:14
帖 子:2899
专家分:0
注 册:2005-11-24
得分:0 
下次 写清楚你是根据什么思路写的~我肯定仔细看~(不然我在猜谜)
虽然程序简单,但不知道你的思路~~ 很难找错误

叁蓙大山:工謪、稅務、嗣發 抱歉:不回答女人的问题
2006-03-16 13:45
仁者无敌
Rank: 1
等 级:新手上路
帖 子:199
专家分:0
注 册:2006-3-5
得分:0 
不知道楼主是怎么想的,要是我啊:先求这是一年中的第几天,然后除以7,这样比较简单吧

I am a programmer !
2006-03-30 13:32
仁者无敌
Rank: 1
等 级:新手上路
帖 子:199
专家分:0
注 册:2006-3-5
得分:0 
好像没我想象的那么简单

I am a programmer !
2006-03-30 13:37



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-50760-1-1.html




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

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