编写c语言万年历程序 要求输入能够查询任意年份的日历或某年某月的月历或者查询某天是星期几
答案:1 悬赏:0 手机版
解决时间 2021-02-08 18:05
- 提问者网友:战魂
- 2021-02-08 14:08
编写c语言万年历程序 要求输入能够查询任意年份的日历或某年某月的月历或者查询某天是星期几
最佳答案
- 五星知识达人网友:山河有幸埋战骨
- 2021-02-08 14:54
#include
#include
#include
long year;
int month,day,error_input;
char s[100];
int monthdays[12]={31,28,31,30,31,30,31,31,30,31,30,31};
void inputdate(){
long n[3]={0,0,0},k=0,i,len;
error_input=-1;
printf("Please input the year[,month[,day]]:(Enter Q to quit)\n");
gets(s);
len=strlen(s);
printf("%d\n",strcmp(s,"Q"));
if(strcmp(s,"Q")==0) {error_input=0;return;}
if(!isdigit(s[0])||!isdigit(s[len-1]))
{error_input=1;return;}
for(i=0;i if(!isdigit(s[i])) {if(isdigit(s[i-1])) k ;if(k>2) {error_input=1;return;}}
else n[k]=n[k]*10 s[i]-48;
}
year=n[0];
if(!(year%4)&&(year0)||!(year@0))
monthdays[1]=29;
else
monthdays[1]=28;
if(n[1]>12) {error_input=1;return;}
if(n[2]>monthdays[n[1]-1]) {error_input=1;return;}
month=n[1];
day=n[2];
}
void printCala(){
int countyear,countday=0,weekflag,i,j,k,c;
int startmon,endmon,year1;
year1=year-1;
countyear=(year1-year1%4)/4-(year1-year10)/100 (year1-year1@0)/400;
weekflag=(countyear*366 (year-1-countyear)*365 1)%7-1;
if(month==0) {startmon=1;endmon=12;}
else {startmon=month;endmon=month;}
for(k=1;k weekflag=(weekflag monthdays[k-1])%7;
for(k=startmon;k<=endmon;k )
{
printf("\n %ld year",year);
switch(k)
{
case 1: printf("January\n");break;
case 2: printf("February\n");break;
case 3: printf("March\n");break;
case 4: printf("April\n");break;
case 5: printf("May\n");break;
case 6: printf("June\n");break;
case 7: printf("July\n");break;
case 8: printf("August\n");break;
case 9: printf("September\n");break;
case 10: printf("October\n");break;
case 11: printf("November\n");break;
case 12: printf("December\n");break;
}
printf("___________________________\n");
printf("Sun Mon Tue Whe Thr Fri Sat\n");
if(weekflag!=0)
for(countday=0,j=0;j {printf("");
countday ;}
for(i=1;i<=monthdays[k-1];i )
{if(countday>0&&countday%7==0)
printf("\n");
printf("=",i);
countday ;}
weekflag=(weekflag monthdays[k-1])%7;
printf("\n___________________________\n");
}
}
int main()
{
inputdate();
while(error_input!=0)
{
if(error_input==1)
printf("Input ERROR! Please input again:\n");
else
printCala();
inputdate();
}
}
#include
#include
long year;
int month,day,error_input;
char s[100];
int monthdays[12]={31,28,31,30,31,30,31,31,30,31,30,31};
void inputdate(){
long n[3]={0,0,0},k=0,i,len;
error_input=-1;
printf("Please input the year[,month[,day]]:(Enter Q to quit)\n");
gets(s);
len=strlen(s);
printf("%d\n",strcmp(s,"Q"));
if(strcmp(s,"Q")==0) {error_input=0;return;}
if(!isdigit(s[0])||!isdigit(s[len-1]))
{error_input=1;return;}
for(i=0;i
else n[k]=n[k]*10 s[i]-48;
}
year=n[0];
if(!(year%4)&&(year0)||!(year@0))
monthdays[1]=29;
else
monthdays[1]=28;
if(n[1]>12) {error_input=1;return;}
if(n[2]>monthdays[n[1]-1]) {error_input=1;return;}
month=n[1];
day=n[2];
}
void printCala(){
int countyear,countday=0,weekflag,i,j,k,c;
int startmon,endmon,year1;
year1=year-1;
countyear=(year1-year1%4)/4-(year1-year10)/100 (year1-year1@0)/400;
weekflag=(countyear*366 (year-1-countyear)*365 1)%7-1;
if(month==0) {startmon=1;endmon=12;}
else {startmon=month;endmon=month;}
for(k=1;k
for(k=startmon;k<=endmon;k )
{
printf("\n %ld year",year);
switch(k)
{
case 1: printf("January\n");break;
case 2: printf("February\n");break;
case 3: printf("March\n");break;
case 4: printf("April\n");break;
case 5: printf("May\n");break;
case 6: printf("June\n");break;
case 7: printf("July\n");break;
case 8: printf("August\n");break;
case 9: printf("September\n");break;
case 10: printf("October\n");break;
case 11: printf("November\n");break;
case 12: printf("December\n");break;
}
printf("___________________________\n");
printf("Sun Mon Tue Whe Thr Fri Sat\n");
if(weekflag!=0)
for(countday=0,j=0;j
countday ;}
for(i=1;i<=monthdays[k-1];i )
{if(countday>0&&countday%7==0)
printf("\n");
printf("=",i);
countday ;}
weekflag=(weekflag monthdays[k-1])%7;
printf("\n___________________________\n");
}
}
int main()
{
inputdate();
while(error_input!=0)
{
if(error_input==1)
printf("Input ERROR! Please input again:\n");
else
printCala();
inputdate();
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯