c语言问题,还请高手帮帮忙!谢谢了!

2024-11-18 07:32:57
推荐回答(1个)
回答1:

去你的空间看了,你的那个程序太繁琐了,所以我重新变了一个,如下:
如果有疑问,给我留言讨论。我在VC6.0下完美运行。

#include
int dayofyear(int y,int m,int d);
void main()
{
while(1)
{
int y,m,d;
printf("请输入年:\n");
scanf("%d",&y);
printf("请输入月:\n");
scanf("%d",&m);
if(m<1||m>12){printf("Input Data Errors!\n");break;}
printf("请输入日:\n");
scanf("%d",&d);
if(d<1||d>31){printf("Input Data Errors!\n");break;}
//dayofyear(int y,int m,int d);
printf("%d月%d日是%d年中的第%d天\n\n\n",m,d,y,dayofyear(y,m,d));
}
}
int dayofyear(int y,int m,int day)
{
int leap,i;
int days[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};
leap=((y%4==0&&y%100!=0)||(y%400==0));
for(i=1;i {
day=day+days[leap][i];
}
return day;
}