求一个C语言编程 要求编写万年历系统

要求如下:1.输入一年号,输出这一年年历
2.判断输出的年号是否是闰年
时间紧急,望高手速来帮忙~希望备注的详细些,我是菜鸟,应付期末实训的~拜托啦~~
好的答案,事后追加分~再次感谢!

第1个回答  2012-06-06
#include <stdio.h>
void main()
{
int year,month,day,days,sum,i,n=0,a;
char c;
redo: printf("请输入年/月/日(例如:2010/1/1):\n");
scanf("%d/%d/%d",&year,&month,&day);
if(month==1&&(day>=32||day<=0))
{
printf("输入有误!1月只能有31天!\n");
goto redo;
}
if(month==2)
{
if((year%400==0)||(year%4==0&&year%100!=0))
{
if(day>=30||day<=0)
{
printf("输入有误!%d年是闰年,二月只能有29天!\n",year);
goto redo;
}
}
else if(day>=29||day<=0)
{
printf("输入有误!%d年是平年,二月只能有28天!\n",year);
goto redo;
}
}
if(month==3&&(day>=32||day<=0))
{
printf("输入有误!3月只能有31天!\n");
goto redo;
}
if(month==4&&(day>=31||day<=0))
{
printf("输入有误!4月只能有30天!\n");
goto redo;
}
if(month==5&&(day>=32||day<=0))
{
printf("输入有误!5月只能有31天!\n");
goto redo;
}
if(month==6&&(day>=31||day<=0))
{
printf("输入有误!6月只能有30天!\n");
goto redo;
}
if(month==7&&(day>=32||day<=0))
{
printf("输入有误!7月只能有31天!\n");
goto redo;
}
if(month==8&&(day>=32||day<=0))
{
printf("输入有误!8月只能有31天!\n");
goto redo;
}
if(month==9&&(day>=31||day<=0))
{
printf("输入有误!9月只能有30天!\n");
goto redo;
}
if(month==10&&(day>=32||day<=0))
{
printf("输入有误!10月只能有31天!\n");
goto redo;
}
if(month==11&&(day>=31||day<=0))
{
printf("输入有误!11月只能有30天!\n");
goto redo;
}
if(month==12&&(day>=32||day<=0))
{
printf("输入有误!12月只能有31天!\n");
goto redo;
}
if(month>=1&&month<=12)
{
if(year%400==0||(year%4==0&&year%100!=0))
printf("%d年是闰年。\n",year);
else printf("%d年是平年。\n",year);
}
if(year>=1901) goto loop1;
else goto loop2;
loop1: for(i=1901;i<year;i++)
{
if(i%400==0||(i%4==0&&i%100!=0))
n++;
}
days=(year-1901-n)*365+n*366;
switch(month)
{
case 1:sum=0;break;
case 2:sum=31;break;
case 3:sum=59;break;
case 4:sum=90;break;
case 5:sum=120;break;
case 6:sum=151;break;
case 7:sum=181;break;
case 8:sum=212;break;
case 9:sum=243;break;
case 10:sum=273;break;
case 11:sum=304;break;
case 12:sum=334;break;
default:printf("一年内只能有12个月!请重新输入!\n");goto redo;
}
a=sum+day+days;
if((year%400==0||(year%4==0&&year%100!=0))&&(month>=3))
a++;
if(a%7==1) printf("%d年%d月%d日是星期二。\n",year,month,day);
if(a%7==2) printf("%d年%d月%d日是星期三。\n",year,month,day);
if(a%7==3) printf("%d年%d月%d日是星期四。\n",year,month,day);
if(a%7==4) printf("%d年%d月%d日是星期五。\n",year,month,day);
if(a%7==5) printf("%d年%d月%d日是星期六。\n",year,month,day);
if(a%7==6) printf("%d年%d月%d日是星期天。\n",year,month,day);
if(a%7==0) printf("%d年%d月%d日是星期一。\n",year,month,day);
goto label;
loop2: for(i=1900;i>year;i--)

{
if(i%400==0||(i%4==0&&i%100!=0))
n++;
}
days=(1900-year-n)*365+n*366;
switch(month)
{
case 1:sum=0;break;
case 2:sum=31;break;
case 3:sum=58;break;
case 4:sum=90;break;
case 5:sum=120;break;
case 6:sum=151;break;
case 7:sum=181;break;
case 8:sum=212;break;
case 9:sum=243;break;
case 10:sum=273;break;
case 11:sum=304;break;
case 12:sum=334;break;
default:printf("一年内只能有12个月!请重新输入!\n");goto redo;
}
if(year%400==0||(year%4==0&&year%100!=0))
a=366-(day+sum)+days;
else a=365-(day+sum)+days;
if((year%400==0||(year%4==0&&year%100!=0))&&(month>=3))
a--;
if(a%7==0) printf("%d年%d月%d日是星期一。\n",year,month,day);
if(a%7==1) printf("%d年%d月%d日是星期天。\n",year,month,day);
if(a%7==2) printf("%d年%d月%d日是星期六。\n",year,month,day);
if(a%7==3) printf("%d年%d月%d日是星期五。\n",year,month,day);
if(a%7==4) printf("%d年%d月%d日是星期四。\n",year,month,day);
if(a%7==5) printf("%d年%d月%d日是星期三。\n",year,month,day);
if(a%7==6) printf("%d年%d月%d日是星期二。\n",year,month,day);
label: printf("Do you want to continue?Y/N:");
getchar();
c=getchar();
if(c=='Y'||c=='y')
{
n=0;
goto redo;
}
}
相似回答