1个回答
展开全部
#include <stdio.h>
#include <string.h>
#include <ctype.h>
long year;
int monthdays[12]={31,28,31,30,31,30,31,31,30,31,30,31};
void inputyear(){
printf("Please input the year:\n");
scanf("%d",&year);
if(!(year%4)&&(year%100)||!(year%400))
monthdays[1]=29;
else
monthdays[1]=28;
}
void printCala(){
int countyear,countday=0,weekflag,i,j,k,c;
int startmon,endmon,year1;
year1=year-1;
countyear=(year1-year1%4)/4-(year1-year1%100)/100+(year1-year1%400)/400;
weekflag=(countyear*366+(year-1-countyear)*365+1)%7-1;
startmon=1;
endmon=12;
for(k=1;k<startmon;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<weekflag;j++)
{printf(" ");
countday++;}
for(i=1;i<=monthdays[k-1];i++)
{if(countday>0&&countday%7==0)
printf("\n");
printf("%3d ",i);
countday++;}
weekflag=(weekflag+monthdays[k-1])%7;
printf("\n___________________________\n");
}
}
int main()
{
inputyear();
printCala();
}
#include <string.h>
#include <ctype.h>
long year;
int monthdays[12]={31,28,31,30,31,30,31,31,30,31,30,31};
void inputyear(){
printf("Please input the year:\n");
scanf("%d",&year);
if(!(year%4)&&(year%100)||!(year%400))
monthdays[1]=29;
else
monthdays[1]=28;
}
void printCala(){
int countyear,countday=0,weekflag,i,j,k,c;
int startmon,endmon,year1;
year1=year-1;
countyear=(year1-year1%4)/4-(year1-year1%100)/100+(year1-year1%400)/400;
weekflag=(countyear*366+(year-1-countyear)*365+1)%7-1;
startmon=1;
endmon=12;
for(k=1;k<startmon;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<weekflag;j++)
{printf(" ");
countday++;}
for(i=1;i<=monthdays[k-1];i++)
{if(countday>0&&countday%7==0)
printf("\n");
printf("%3d ",i);
countday++;}
weekflag=(weekflag+monthdays[k-1])%7;
printf("\n___________________________\n");
}
}
int main()
{
inputyear();
printCala();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询