C言語に基づくカレンダー

28688 ワード

大学1年生はちょうど数ヶ月C言語を学んだ後に2日間の課程の設計を書いて、今見たところ書くのは少し幼稚で、風格は乱れていますが、しかしも心を見ることができます.思い返しに残る.

#include 
#include 
#include 
#include
int judge(int year)  //          
{
 int a;
 if(year%100==0)
  if(year%400==0)
   a=1;
  else a=0;
 else if(year%4==0)
  a=1;
     else a=0;
 return(a);
} 



int weekday(int year)  //     1 1       
{
 int a,b,c,d;
 long day;
 year--;
 a=year/400;
 b=(year%400)/100;
 c=(year%100)/4;
 day=365*year+97*a+24*b+c;  //   1 1    1 1 (   )    
 d=day%7;
 d++;                        //   1 1    
 return(d);
}




int monthdays(int year,int i)  //            
{ 
 int a,monthday;
 a=judge(year);
 switch(i)
    {
        case  1:monthday=31;break;
        case  2:monthday=28+a;break;
        case  3:monthday=31; break;
        case  4:monthday=30; break;
        case  5:monthday=31;break;
        case  6:monthday=30;break;
  case  7:monthday=31;break;
        case  8:monthday=31;break;
        case  9:monthday=30;break;
        case 10:monthday=31;break;
        case 11:monthday=30;break;
        case 12:monthday=31;break;
    }
    return(monthday);
}
int main()
{  
    int a;
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
    //SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_GREEN);//    
    system("color 0A");
    printf("                                                                   
"
); printf(" ┏━━━━━━━━━━━━━━━━━━━━┓
"
); printf(" ┃ ┃
"
); printf(" ┗━━━━━━━━━━━━━━━━━━━━┛
"
); printf("
"
); printf("
"
); printf(" ┏━━━━━━━━━━━━━━━━━━━━┓
"
); printf(" ┃ 1 ┃
"
); printf(" ┗━━━━━━━━━━━━━━━━━━━━┛
"
); printf(" ┏━━━━━━━━━━━━━━━━━━━━┓
"
); printf(" ┃ 2 ┃
"
); printf(" ┗━━━━━━━━━━━━━━━━━━━━┛
"
); printf(" ┏━━━━━━━━━━━━━━━━━━━━┓
"
); printf(" ┃ 3 ┃
"
); printf(" ┗━━━━━━━━━━━━━━━━━━━━┛
"
); printf("
"
); printf("
"
); printf("
"
); do{ printf(" 1 2 3.
"
); scanf("%d",&a); if(a!=1 && a!=2 && a!=3) printf(" , 。
"
); }while(a!=1 && a!=2 && a!=3); // 1 if(a==1) { int year,i,j,k,s,firstday,monthday; HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); //system("color 3"); system("cls"); do{ printf(" :
"
); scanf("%d",&year); if(year<=1) printf(" , 。
"
); }while(year<=1); system("cls"); s=judge(year); if (s==1) printf("%d , 366 , :
"
,year); else printf("%d , 365 , :
"
,year); printf("
"
); firstday=weekday(year); for(i=1;i<=12;i++) //i { monthday=monthdays(year,i); printf(" %d
"
,i); printf("
"
); SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);// printf(" "); SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY| FOREGROUND_GREEN);// printf("
"
); for(j=0;j%7;j++) { printf(" "); // 1 } for(k=1;k<=monthday;k++) { if((k+firstday)%7==1) { HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);// printf("%-4d",k); } else { HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY| FOREGROUND_GREEN);// printf("%-4d",k); } SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);// if((k+firstday)%7==0) printf("
"
); } firstday=(firstday+monthday)%7; // 1 printf("
"
); printf("
"
); } } // 21 , , if(a==2) { int year,i,j,p,k,s,firstday,monthday,month,day=0; //day=0 , HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); system("cls"); do{ day=0; printf(" , 2014,5 2014 5 :
"
); scanf("%d,%d,%d",&year,&month,&day); if(year<=1||month<1||month>13||day!=0) printf(" , 。
"
); }while(year<=1||year>9999||month<1||month>13||day!=0); system("cls"); s=judge(year); if (s==1) printf("%d , 366 , %d %d
"
,year,month); else printf("%d , 365 , %d %d
"
,year,month); printf("
"
); firstday=weekday(year); for(i=1;i<13;i++) //i { system("cls"); monthday=monthdays(year,i); printf(" %d
"
,i); printf("
"
); SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);// printf(" "); SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY| FOREGROUND_GREEN);// printf("
"
); for(j=0;j%7;j++) { printf(" "); // 1 } for(k=1;k<=monthday;k++) { if((k+firstday)%7==1) { HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);// printf("%-4d",k); } else { HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY| FOREGROUND_GREEN);// printf("%-4d",k); } SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);// if((k+firstday)%7==0) printf("
"
); } firstday=(firstday+monthday)%7; // 1 printf("
"
); printf("
"
); if(i==month) { for(p=0;p%7;p++) { printf(" "); // 1 } break; } } printf("
"
); SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE);// if (s==1) printf("%d , 366 , %d %d
"
,year,year,month); else printf("%d , 365 , %d %d
"
,year,year,month); } // 31 , , , , if(a==3) { int year,i,j,p,k,s,firstday,monthday,month,day=0,whichday; // HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); system("cls"); do{ printf(" , 2014,5,30 2014 5 30
"
); scanf("%d,%d,%d",&year,&month,&day); if(year<=1||month<1||month>13||day==0) printf(" , 。
"
); }while(year<=1||month<1||month>13||day==0); system("cls"); s=judge(year); if (s==1) printf("%d , 366 , %d %d
"
,year,month); else printf("%d , 365 , %d %d
"
,year,month); printf("
"
); firstday=weekday(year); for(i=1;i<13;i++) //i { system("cls"); monthday=monthdays(year,i); printf(" %d
"
,i); printf("
"
); SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);// printf(" "); SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY| FOREGROUND_GREEN);// printf("
"
); for(j=0;j%7;j++) // { printf(" "); // 1 } for(k=1;k<=monthday;k++) { if((k+firstday)%7==1) { HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); if(k==day) { SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);// k , printf("%-4d",k); whichday=7; // } else { SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);// printf("%-4d",k); } } else { HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); if(k==day) { SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); // k , printf("%-4d",k); whichday=(k+firstday)%7-1; // } else { SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY| FOREGROUND_GREEN);// printf("%-4d",k); } } SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); // if((k+firstday)%7==0) printf("
"
); } firstday=(firstday+monthday)%7; // 1 printf("
"
); printf("
"
); if(i==month) { for(p=0;p%7;p++) { printf(" "); // 1 } break; } } printf("
"
); SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE);// if (s==1) printf("%d , 366 , %d %d %d%d
"
,year,year,month,day,whichday); else printf("%d , 365 , %d %d %d%d
"
,year,year,month,day,whichday); } return 0; }

2014年3月