c语言 万年历 求助
程序代码:
#include<stdio.h> #include<stdlib.h> int runnian(int year) { if(year%4==0&&year%100!=0||year%400==0) return 1; else return 0; } int day1(int year,int month) { int a[12]={31,28,31,30,31,30,31,31,30,31,30,31}; if(runnian(year)) a[1]=29; return a[month-1]; } int day2(int year,int month,int day) { int i,sum=0; for(i=1;i<month;i++) { sum+=day1(year,i); } sum+=day; return sum; } int week1(int year,int month,int day) { int number=(year-1)+(year-1)/4-(year-1)/100+(year-1)/400+day2(year,month,day); number%=7; return number; } char *week2(int number) { switch(number) { case 0: return "星期日"; case 1: return "星期一"; case 2: return "星期二"; case 3: return "星期三"; case 4: return "星期四"; case 5: return "星期五"; case 6: return "星期六"; default: return "错误!请重新输入。"; } } void x1(int year,int month,int day) { int number=week1(year,month,day); if(runnian(year)) printf("闰年"); else printf("平年"); printf(" %d 年 %d 月 %d 日%10s\n\n",year,month,day,week2(number)); } int x3(int year,int month,int day) { if(year<0||month<1||month>12||day<1||day>day1(year,month)) return 0; else return 1; } void nianli(int year) { int i; printf("\n"); for(i=1;i<=12;i++) { if(runnian(year)) printf("闰年"); else printf("平年"); printf(" %d 年 %d 月\n\n",year,i); } } void rili(int year,int month,int day) { printf("\n"); x1(year,month,day); } void main() { int year,month,day,a,b; while(1) { printf("\n\n\n\n"); printf("*****************************************************************\n\n"); printf(" * * \n"); printf(" 欢迎进入万年历查询系统\n"); printf(" * * \n\n"); printf("*****************************************************************\n\n\n"); printf(" 1 年历 2 月历 3 日历 4 退出\n"); printf(" 请输入您的选择《1~4》,按回车键确定:"); scanf("%d,&b"); switch(b) { case 1: printf("请输入您要查询的年份:"); scanf("%d,&year"); a=x3(year,1,1); if(a==0) { printf("错误!请您重新输入。\n"); break; } nianli(year); break; case 2: printf("请输入您要查询的年和月,中间用空格隔开:"); scanf("%d%d",&year,&month); a=x3(year,month,1); if(a==0) { printf("错误!请您重新输入。\n"); break; } break; case 3: printf("请输入您要查询的年月日,中间用空格隔开:"); scanf("%d%d%d",&year,&month,&day); a=x3(year,month,day); if(a==0) { printf("错误!请您重新输入。\n"); break; } rili(year,month,day); break; case 4: exit(0); default: printf("错误!请您重新输入。\n\n"); } } }运行时,报错~~~~~