请输入一个年份输出农历
#include stdlib.h
#include stdio.h
#include conio.h
int IsLeapYear(int);
main()
{
int i;
int day;
int year;
int temp;
int temp_i;
long int Year_days = 0;
int Year_Start = 1;
int Per_Year_Days;
int month_day[]={31,28,31,30,31,30,31,31,30,31,30,31,29};
printf("输入年份: "); /*从键盘输入年份*/
scanf("%d",year);
while(Year_Start year)
{
if( IsLeapYear( Year_Start ) ) /*判断输入年份否闰年*/
Per_Year_Days = 366;
else
Per_Year_Days = 365;
Year_days = Year_days + Per_Year_Days;
Year_Start++;
} /*while循环计算从1输入年份共有多少天*/
for( temp = 1; temp =12; temp++ )
{ /*for循环打印出该年每月日历*/
switch( temp )
{
case 1:
printf(" January(%d)n",year);
break;
case 2:
printf(" February(%d)n",year);
break;
case 3:
printf(" March(%d)n",year);
break;
case 4:
printf(" April(%d)n",year);
break;
case 5:
printf(" May(%d)n",year);
break;
case 6:
printf(" June(%d)n",year);
break;
case 7:
printf(" July(%d)n",year);
break;
case 8:
printf(" August(%d)n",year);
break;
case 9:
printf(" September(%d)n",year);
break;
case 10:
printf(" October(%d)n",year);
break;
case 11:
printf(" November(%d)n",year);
break;
case 12:
printf(" December(%d)n",year);
break;
}
i = Year_days % 7;
printf("Mon Tue Wed Thu Fri Sat Sunn");
if( i != 0 )
for( temp_i = 0; temp_i i; temp_i++)
printf(" ");
day = 1;
if( IsLeapYear(year) temp == 2) /*闰年2月*/
while( day = month_day[12] )
{
if( day 1 )
if( Year_days % 7 == 0 )
printf("n");
if( day = 10 )
printf("%-4d",day);
else
printf("%-4d",day);
Year_days++;
day++;
}
else /*闰年*/
while (day = month_day[temp-1])
{
if( day 1 )
if( Year_days % 7 == 0 )
printf("n");
if( day =10 )
printf("%-4d",day);
else
printf("%-4d",day);
Year_days++;
day++;
}
printf("n");
if( getch() == 'q' ) /*输入Q结束*/
exit(0);
}
getch();
}
int IsLeapYear( int year ) /*判断否闰年*/
{
if ((year %4 == 0) (year % 100 != 0) ||
(year % 400 == 0) )
return 1;
else
return 0;
}
请输入一个年份输出农历相关文章: