当前位置导航:炫浪网>>网络学院>>编程开发>>C++教程>>C++进阶与实例

打印日历的一个小程序

    #include<stdio.h>
    #include<conio.h>
    main()
    {int i=0,m=0,k,j,n=0,l,first;
    int x[3]={1,25,50},y=1;
    int day(int);
    int a[2][13]={{31,28,31,30,31,30,31,31,30,31,30,31},
           {31,29,31,30,31,30,31,31,30,31,30,31}};
    printf("\n\nplease input the year:");
    scanf("%d",&i); l=i;
    first=day(i);
    if(i%4==0)k=1;
    else k=0;
    i=0;
    while(m++<2)
    {clrscr();
    printf("                               %d",l);
     for(;i<6*m;i++)
    {
    if(i<6)y=(i/3)*8+2; else y=((i-6)/3)*8+2 ;
    gotoxy(x[i%3],y);
    printf("        %d",i+1);
    gotoxy(x[i%3],++y);
    printf(" su mo tu we th fr sa");
    gotoxy(x[i%3],++y);
    for(n=0;n<first;n++)
    printf("   ");
    for(j=1;j<=a[k][i];j++)
    {printf("%3d",j);
    if((first+j)%7==0)
    gotoxy(x[i%3],++y);}

    first=(first+a[k][i])%7;
    }  if(m==1) printf("\n\nany key to continue");
      else printf("\n\nAny key to end");
    getch();     }
    }


    day(int i)
    {int k,s=0;
    if(i>2000)
    {for(k=2000;k<i;k++)
    if(k%4==0) s=s+366;
    else s=s+365;
    return((s+6)%7);}
    else if(i=2000) return(5);
         else
         {for(k=i;k<2000;k++)
         if(k%4==0)s=s+366;
         else s=s+365;
         return(7-(s+6)%7);}
      }

 

 

相关内容
赞助商链接