#include "stdio.h"
#include "math.h"
#include "stdlib.h"
/*
两大问题:
1、如何确定一个月的第一天是星期几,
2、如何确定一年的第一天是星期几
*/
int isleap=0; /*判断是否为闰年,C语言内默认没有bool变量,所以使用int型*/
void IsLeap(int Y)
{
if((Y/4==0&&Y/100!=0)||(Y/400==0))
{
isleap=1;
}
}
void IsLeap(int Y);
main()
{
int Year,i,j,m,Space,LastDay=0;
char Month[12][10]={"January","February","March","April","May","June","July","August","September","October","November","December"};
char Week[7][4]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
while(1)
{
printf("please input a Between 1900 And 2500 number:");
scanf("%d",&Year);
if(Year>=1900&&Year<=2500)
break;
else
printf("You Input Is Error!Please Agian Input Between 1900 And 2500 numbers!");
}
IsLeap(Year); /*判断是否为闰年*/
/*输出部分*/
for(m=0;m<12;m++)
{
printf("\t %s\n",Month[m]); /*输出月份*/
printf("\t---------\n");
for(i=0;i<7;i++) /*输出星期几*/
{
printf("%4s",Week);
}
printf("\n-----------------------------\n");
for(Space=1;Space<=4*LastDay;Space++)
{
printf(" ");/*输出空格数目,这里的算法怎么算呢?这一步被难住了*/
}
for(j=1;j<=Days(m);j++) /*输出日历*/
{
printf("%4d",j);
if((j+LastDay)%7==6)
printf("\n");
}
LastDay=(j-1)%7;
printf("\n-----------------------------\n\n");
getch();
}
}
int Days(int month)
{
int days=0;
switch(month+1)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: days=31;break;
case 2:
if(isleap) /*判断是否为闰年再返回天数*/
days=29;
else
days=28;
break;
default:days=30;break;
}
return days;
}
|