Chinaunix首页 | 论坛 | 博客
  • 博客访问: 37628
  • 博文数量: 16
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 82
  • 用 户 组: 普通用户
  • 注册时间: 2015-04-16 19:30
个人简介

嵌入式Linux编程 Android软件开发

文章分类

全部博文(16)

文章存档

2015年(16)

分类: C/C++

2015-04-30 18:00:17


点击(此处)折叠或打开

  1. #include <stdio.h>
  2.   
  3. int main(void)
  4. {
  5.     int a, i, j, n, k, t, w, x, y, z;
  6.     static int d[13][78];
  7.     int m[14] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  8.     char wst[] = " Sun Mon Yue Wed Thu Fri Sat ";
  9.     printf("Please enter the year: ");
  10.     scanf("%d", &y);
  11.   
  12.     if(y%4==0 && y%100!=0 || y%400==0) /*闰年的二月为29天*/
  13.         m[2] = 29;
  14.     w = (y+(y-1)/4-(y-1)/100+(y-1)/400)%7; /*计算y年元旦为星期w*/
  15.     for(i=1; i<=12; i++)
  16.     {
  17.         a = 1;
  18.         for(j=1; j<=6; j++)
  19.         {
  20.             for(k=0; k<=6; k++)
  21.             {
  22.                 while(k<w) k=k+1;
  23.                 d[i][j*10+k] = a; /*计算i月的第j个星期的星期w的日期为a*/
  24.                 a=a+1;
  25.                 w = k+1;
  26.                 if(w==7) w=0;
  27.                 if(a>m[i]) break;
  28.             }
  29.             if(a>m[i]) break;
  30.         }
  31.     }
  32.     printf("input x(1,2,3,4,5,6): ");
  33.     scanf("%d", &x);
  34.     for(k=1; k<=16*x-3; k++)
  35.         printf(" ");
  36.     printf("=====%d=====\n", y); /*打印年号*/
  37.     for(n=1; n<=12/x; n++)
  38.     {
  39.         t = x*(n-1)+1;
  40.         printf("\n ");
  41.         for(z=1; z<=x; z++)
  42.         {
  43.             for(k=1; k<=15; k++)
  44.                 printf(" ");
  45.             printf("%2d", t+z-1); /*打印月号*/
  46.             for(k=1; k<=14; k++)
  47.                 printf(" ");
  48.         }
  49.         printf("\n ");
  50.         for(z=1; z<=x; z++) /*按一横排x个月格式打印*/
  51.             printf("%s", wst); /*打印星期标题*/
  52.         for(j=1; j<=6; j++)
  53.         {
  54.             printf("\n ");
  55.             for(i=t; i<=t+x-1; i++)
  56.             {
  57.                 printf(" ");
  58.                 for(k=0; k<=6; k++)
  59.                     if(d[i][j*10+k]==0) /*空缺日期位置打印空格*/
  60.                         printf(" ");
  61.                     else
  62.                         printf("%4d", d[i][j*10+k]);/*打印日期*/
  63.             }
  64.         }
  65.     }
  66.   
  67.     return 0;
  68. }
Linux环境下运行结果如下:


阅读(1116) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

安静的美男子2015-04-30 18:01:12

文明上网,理性发言...