|
|
#2
寒风中的细雨2010-04-22 11:51
#include <stdio.h>
int main() { int year, days, sum, sum1; int a[12] = {31,29,31,30,31,30,31,31,30,31,30,31}; printf("input the year:"); scanf("%d", &year); if( (year%4==0&&year%100!=0) || year%400==0 ) days=366; else { days = 365; a[1] = 28; } if( year>=2000 ) sum = (days%7+6)%7; else sum = (6-days%7)%7; printf("======================\n"); printf("\t%d年\n", year); printf("======================\n"); int i, j, k, flag=1, count=0; for(i=1; i<=12; i=i+2) { printf("%d月",i); printf("\t\t\t\t\t%d月\n",i+1); printf(" Su Mo Tu We Th Fr Sa"); printf("\t\t Su Mo Tu We Th Fr Sa\n"); //////////////////////////////////////////////////////// sum1 = (sum+a[i-1])%7; for( j=1; j<=sum; j++) printf(" "); for( k=1,j=1; j<=a[i-1]; j++) { printf("%4d", j); if( (j+sum)%7==0 || j==a[i-1] ) { count = 0; if( j==a[i-1] ) while( (j+sum+count)%7!=0 ) { printf(" "); count++; } printf("\t\t"); if( flag==1 ) { for( count=1; count<=sum1; count++ ) printf(" "); } for( ; k<=a[i]; ) { flag++; printf("%4d", k); if( (k+sum1)%7==0 ) { k++; break; } k++; } printf("\n"); } } if( k!=a[i]+1 ) { printf("\t\t\t\t\t"); do { printf("%4d",k); k++; }while( k!=a[i]+1 ); printf("\n"); } flag=1; sum = (sum1+a[i])%7; printf("\n"); } return 0; } |
#include<stdio.h>
void main()
{
int year,days=0,sum,i,day=0,j;
printf("输入年份:");
scanf("%d",&year);
if(year>=2000){
for(i=2000;i<year;i++){
if(i%4==0&&i%100!=0||i%400==0)
days+=366;
else days+=365;
}
sum=(days%7+6)%7;
}
else if(year<2000){
for(i=1999;i>=year;i--){
if(i%4==0&&i%100!=0||i%400==0)
days+=366;
else days+=365;
}
sum=(6-days%7)%7;;
}
printf("===============================\n");
printf("%4d 年日历\n",year);
printf("===============================\n");
for(i=1;i<=12;i++){
printf("%d月\n",i);
printf(" Su Mo Tu We Th Fr Sa\n");
switch(i){
case 1:case 3:case 5:case 7:case 8:case 10:case 12: day=31; break;
case 2: {
if(year%4==0&&year%100!=0||year%400==0)
day=28;
else day=29;
} break;
case 4:case 6:case 9:case 11: day=30; break;
}
for(j=1;j<=sum;j++)
printf(" ");
for(j=1;j<=day;j++){
printf("%4d",j);
if((j+sum)%7==0)
printf("\n");
}
sum=(sum+day)%7;
printf("\n");
}
}
这个万年历只能竖着打,那个高手能指点一下改成两个月打一行