#include <stdio.h>
#include <stdlib.h>
void Data( int year, int month )
{
char *cmonth[12] = {"Jaunary", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"};
char *cweek[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
int imonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
//Base on 2004/1/1 THU
int week = 4;
int baseyear = 2004;
int i, j;
while( ( year - baseyear ) != 0 )
{
if( ( year - baseyear ) > 0 )
{
week++;
if( ( baseyear % 4 ) == 0 )
week++;
baseyear++;
if( week > 6 )
week -= 7;
}
else if( ( year - baseyear ) < 0 )
{
week--;
baseyear--;
if( ( baseyear % 4 ) == 0 )
week--;
if( week < 0 )
week += 7;
}
}
if( ( baseyear % 4 ) == 0 )
imonth[1]++;
for( i=0; i<12; i++ )
{
if( (i+1) == month || month == 0 )
{
printf("\n%s\n", cmonth[i]);
for( j=0; j<7; j++ )
{
printf("%3s ", cweek[j]);
}
printf("\n");
for( j=0; j<week; j++ )
printf(" ");
for( j=1; j<=imonth[i]; j++ )
{
printf("%3d ", j);
if( week == 6 )
{
week -= 7;
printf("\n");
}
week++;
}
}
}
printf("\n");
system("pause");
}
int main()
{
int year, month;
int command = 1;
while( command != 0 )
{
printf("請輸入要列印月曆或年曆 ( 1>月曆 2>年曆 0>結束 ):");
scanf("%d", &command);
if( command == 1 )
{
printf("請輸入西元年:");
scanf("%d", &year);
printf("請輸入月份:");
scanf("%d", &month);
Data( year, month );
}
else if( command == 2 )
{
printf("請輸入西元年:");
scanf("%d", &year);
month = 0;
Data( year, month );
}
else if( command == 0 )
{
exit(0);
}
else
{
printf("\nError command.\n");
}
}
}
可到http://knight.fcu.edu.tw/~d9223202/data.c
--
中文書是什麼..可以吃嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.62.13.231