小弟刚学语言,以下为小弟刚编的测算星期的程序--------输入日期即自动测试该日期是星期几?
请问:
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编辑过]