You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nianli/年历显示(修改).c

334 lines
5.9 KiB

6 years ago
#include<stdio.h>
#include<time.h>
void menu();
void year_calendar();
void year_month_calendar();
void year_month_day_calendar();
int main()
{
int choice;
menu();
printf("<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%d",&choice);
switch(choice)
{
case 1:year_calendar();break ;
case 2:year_month_calendar();break;
case 3:year_month_day_calendar();break;
}
return 0;
}
void menu()
{
printf("\n-------------------------------------------------------\n");
printf(" <20><>ӭ<EFBFBD><D3AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯϵͳ \n");
printf(" 1:<3A><>ѯij<D1AF><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD> \n");
printf(" 2:<3A><>ѯij<D1AF><C4B3>ij<EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD> \n");
printf(" 3:<3A><>ѯij<D1AF><C4B3><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ \n");
printf(" 4:<3A>˳<EFBFBD> \n");
printf("-------------------------------------------------------\n");
}
void year_calendar()
{
int year,day,i,j,k,n,m,q,month_one_weekday[13];//day--<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>һ<EFBFBD><D2BB>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>죻 month_one_weekday[13]--ÿ<><C3BF><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD>
int month_day[13]; //month_day[13]---<2D><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>ÿ<EFBFBD>¹<EFBFBD><C2B9>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD>
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>");
scanf("%d",&year);
day=0;
for(i=1;i<=year-1;i++)
{
if( year%400==0 || (year%4==0&&year%100!=0) )
n=366;
else n=365;
day=day+n;
}
month_day[0]=0;
for(i=1;i<=12;i++)
{
switch(i)
{
case 1:case 3:case 5:case 7:
case 8:case 10:case 12: month_day[i]=31;break;
case 4:case 6:case 9:case 11: month_day[i]=30;break;
case 2:if( year%400==0 || (year%4==0&&year%100!=0) )
month_day[i]=29;
else month_day[i]=28;
break;
}
day=day+month_day[i-1];
if((day+1)%7==0)
month_one_weekday[i]=7;
else month_one_weekday[i]=(day+1)%7;//month_one_weekday[i]:<3A><>i<EFBFBD><69><EFBFBD>µĵ<C2B5>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD>
}
for(i=1;i<=12;i++)//ÿѭ<C3BF><D1AD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>
{
printf("\n\n");
printf("\n%2i<32><69>\n\tSun\tMon\tTue\tWed\tThur\tFri\tSat\n",i);
for(j=1,m=0;j<=month_day[i];j++)//j:ÿ<><C3BF><EFBFBD>µ<EFBFBD>ÿһ<C3BF>죻 ?m<><6D><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if(j==1)
{
q=month_one_weekday[i]-1;
for(k=1;k<=q;k++)
printf("\t");
printf("\t%d\t",j);m=q+1;
}
else { printf("%d\t",j);m++;}
if(m%7==0)
printf("\n\t ");
}
}
printf("\n");
main();
}
void year_month_calendar()
{
int year,month,day=0;
int i,j,k,n,m,q;
int month_day[13],month_one_weekday[13];
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>");
scanf("%d%d",&year,&month);
day=0;
for(i=1;i<=year-1;i++)
{
if( year%400==0 || (year%4==0&&year%100!=0) )
n=366;
else n=365;
day=day+n;
}
month_day[0]=0;
for(i=1;i<=12;i++)
{
switch(i)
{
case 1:case 3:case 5:case 7:
case 8:case 10:case 12: month_day[i]=31;break;
case 4:case 6:case 9:case 11: month_day[i]=30;break;
case 2:if( year%400==0 || (year%4==0&&year%100!=0) )
month_day[i]=29;
else month_day[i]=28;
break;
}
day=day+month_day[i-1];
if((day+1)%7==0) month_one_weekday[i]=7;
else month_one_weekday[i]=(day+1)%7;//month_one_weekday[i]:<3A><>i<EFBFBD><69><EFBFBD>µĵ<C2B5>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD>
}
printf("%d<><64><EFBFBD>ĵ<EFBFBD>%d<><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n",year,month);
printf("Ҫ<EFBFBD><EFBFBD>ѯ<EFBFBD>ĵ<EFBFBD><EFBFBD>¹<EFBFBD><EFBFBD>ƶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>죺%d\n",month_day[month]);
printf("\n%2i<32>£<EFBFBD>Sun\tMon\tTue\tWed\tThur\tFri\tSat\n",month);
for(j=1,m=0;j<=month_day[month];j++)//j:ÿ<><C3BF><EFBFBD>µ<EFBFBD>ÿһ<C3BF>죻 ?m<><6D><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if(j==1)
{
q=month_one_weekday[month]-1;
for(k=1;k<=q;k++)
printf("\t");
printf("\t%d\t",j);m=q+1;
}
else { printf("%d\t",j);m++;}
if(m%7==0)
printf("\n\t");
}
printf("\n");
main();
}
void year_month_day_calendar()
{
int year,month,dayy,day,day1,day2,weekday,flag,n1,n2,n,i;//n--<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>죬dayy--<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>day
int month_day[13];
struct tm *local;
time_t t;
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>գ<EFBFBD>");
scanf("%d%d%d",&year,&month,&dayy);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǣ<EFBFBD>%d<><64>%d<><64>%d<>գ<EFBFBD>",year,month,dayy);
if(month==1)
{
if(dayy==1)
printf("Ԫ<EFBFBD><EFBFBD>");
}
else if(month==2)
{
if(dayy==14)
printf("<EFBFBD><EFBFBD><EFBFBD>˽<EFBFBD>");
}
else if(month==3)
{
switch(dayy)
{
case 8:printf("<EFBFBD><EFBFBD>Ů<EFBFBD><EFBFBD>");break;
case 12:printf("ֲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");break;
}
}
else if(month==4)
{
if(dayy==1)
printf("<EFBFBD><EFBFBD><EFBFBD>˽<EFBFBD>");
}
else if(month==5)
{
switch(dayy)
{
case 1:printf("<EFBFBD>Ͷ<EFBFBD><EFBFBD><EFBFBD>");break;
case 4:printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");break;
}
}
else if(month==6)
{
if(dayy==1)
printf("<EFBFBD><EFBFBD>ͯ<EFBFBD><EFBFBD>");
}
else if(month==7)
{
if(dayy==1)
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
else if(month==8)
{
if(dayy==1)
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
else if(month==9)
{
if(dayy==10)
printf("<EFBFBD><EFBFBD>ʦ<EFBFBD><EFBFBD>");
}
else if(month==10)
{
if(dayy==1)
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
else if(month==11)
{
;
}
else
{
if(dayy==25)
printf("ʥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
day=0;
for(i=1;i<=year-1;i++)
{
if( year%400==0 || (year%4==0&&year%100!=0) )
n=366;
else n=365;
day=day+n;
}
day1=day;
month_day[0]=0;
for(i=1;i<=12;i++)
{
switch(i)
{
case 1:case 3:case 5:case 7:
case 8:case 10:case 12: month_day[i]=31;break;
case 4:case 6:case 9:case 11: month_day[i]=30;break;
case 2:if( year%400==0 || (year%4==0&&year%100!=0) )
month_day[i]=29;
else month_day[i]=28;
break;
}
}
for(i=1,n1=0;i<=month-1;i++)
day1=day1+month_day[i];
day1=day1+dayy;
n1=day1; //n1--<2D><>Ԫ1<D4AA><31>1<EFBFBD><31>1<EFBFBD>գ<EFBFBD><D5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
t=time(NULL);
local=localtime(&t);
year=local->tm_year+1900;
month=local->tm_mon+1;
dayy=local->tm_mday;
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǣ<EFBFBD>%d<><64>%d<><64>%d<>ա<EFBFBD>\n",year,month,dayy);
day2=day;
for(i=1;i<=12;i++)
{
switch(i)
{
case 1:case 3:case 5:case 7:
case 8:case 10:case 12: month_day[i]=31;break;
case 4:case 6:case 9:case 11: month_day[i]=30;break;
case 2:if( year%400==0 || (year%4==0&&year%100!=0) )
month_day[i]=29;
else month_day[i]=28;
break;
}
}
for(i=1,n2=0;i<=month-1;i++)
day2=day2+month_day[i];
day2=day2+dayy;
n2=day2; //n2--<2D><>Ԫ1<D4AA><31>1<EFBFBD><31>1<EFBFBD>գ<EFBFBD><D5A3><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(n2>n1)
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ھ<EFBFBD><EFBFBD>뵱ǰϵͳ<EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD><EFBFBD><EFBFBD>%d<>\n",n2-n1);
else
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ھ<EFBFBD><EFBFBD>뵱ǰϵͳ<EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD><EFBFBD><EFBFBD>%d<>\n",n1-n2);
int week;
week=n1%7-1;
switch(week)
{
case 0:
{
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
break;
}
case 1:
{
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ");
break;
}
case 2:
{
printf("<EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD>");
break;
}
case 3:
{
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
break;
}
case 4:
{
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
break;
}
case 5:
{
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
break;
}
case 6:
{
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
break;
}
}
printf("\n");
main();
}