又要麻烦高手们了~~~自己写的一个小程序,不知道错在哪里
#include<stdio.h>int b(long year, long presentyear,int month,int day)//计算天数
{ int sum=0,leap=0;
if(month==2&&day==29)
{
if(presentyear%400==0||(presentyear%4==0&&presentyear%100!=0))
{
while((presentyear+=4)<=year)
{
sum+=5;
}
return sum;
}
else
{
printf("had not the day!\n");
return -10;
}
}
else if(month==1||(month==2&&(day!=29)))
{
while(presentyear++<year)
{
if(presentyear%400==0||(presentyear%4==0&&presentyear%100!=0))/*判断是不是闰年*/
leap=1;
else
leap=0;
if(leap==1)/*如果是闰年,应该多1天*/
sum+=2;
else
sum+=1;
}
return sum;
}
else
{
while((presentyear+=1)<=year)
{
if(presentyear%400==0||(presentyear%4==0&&presentyear%100!=0))/*判断是不是闰年*/
leap=1;
else
leap=0;
if(leap==1)/*如果是闰年,应该多1天*/
sum+=2;
else
sum+=1;
}
return sum;
}
}
int c(int week,long year,long presentyear,int month,int day)//计算当天星期
{ int n;
n=b(year,presentyear,month,day)+week;
return n;
}
void main()
{ int presentyear,age,year,presentage,month,day,week,flag;
printf("this program gives your age in a year ,and your birthday week in that year\n");
printf("what year is this?\n");
scanf("%d",&presentyear);
printf("which year you want know?\n");
scanf("%d",&year);
printf(" what is your present age?\n");
scanf("%d",&presentage);
printf("what is month and day\n");
scanf("%d%d",&month,&day);
printf("what is your birthday (month,day)and which week in that day?\n");
printf("monday=1\ttuesday=2\twednesday=3\tthusday=4\tfriday=5\tsturday=6\tsunday=7\n");
scanf("%d",&week);
age=year+presentage-presentyear;
printf("you well be %d year in the %d\n",age ,year);
printf("your birthday month %d day %d is \n",month,day);
flag=c(week,year,presentyear,month,day);
switch(flag%7)
{ case 0:printf("%d\n",7);break;
case 1:printf("%d\n",1);break;
case 2:printf("%d\n",2);break;
case 3:printf("%d\n",3);break;
case 4:printf("%d\n",4);break;
case 5:printf("%d\n",5);break;
case 6:printf("%d\n",6);break;
default:printf("error!\n");break;
}
}
[[it] 本帖最后由 tiw 于 2008-5-29 16:26 编辑 [/it]]