用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - c代码库

c语言日历

2012-10-06 作者: 神马举报

[c]代码库

#include
int main ( void )
{
	char *weeks[7]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
	char *ss[7]={"日","一","二","三","四","五","六"};

	int year;
	int month;
	int day;
	int week;
	int monthday;
	int allday;

	allday=0;

	int i;
	int k;
	int h;

	h=0;

	printf ( "输入查询时期:" );

	scanf ( "%d %d %d",&year,&month,&day );


	for ( i=1900; i
{
	allday=allday+365;
	if ( ( i%4==0 ) && ( i%100!=0 ) || ( i%400==0 ) )
		{
			allday++;
		}

	}

	switch ( month )
{
case 1:
	monthday=31;
	break;
case 2:
	allday+=31;
	monthday=28;
	break;
case 3:
	allday+=31+28;
	monthday=31;
	break;
case 4:
	allday+=31+28+31;
	monthday=30;
	break;
case 5:
	allday+=31+28+31+30;
	monthday=31;
	break;
case 6:
	allday+=31+28+31+30+31;
	monthday=30;
	break;
case 7:
	allday+=31+28+31+30+31+30;
	monthday=31;
	break;
case 8:
	allday+=31+28+31+30+31+30+31;
	monthday=31;
	break;
case 9:
	allday+=31+28+31+30+31+30+31+31;
	monthday=30;
	break;
case 10:
	allday+=31+28+31+30+31+30+31+31+30;
	monthday=31;
	break;
case 11:
	allday+=31+28+31+30+31+30+31+31+30+31;
	monthday=30;
	break;
case 12:
	allday+=31+28+31+30+31+30+31+31+30+31+30;
	monthday=31;
	break;

}
if ( ( year%4==0 ) && ( year%100!=0 ) || ( year%400==0 ) )
{
	if ( month==2 ) monthday=29;
		if ( month>2 ) allday++;
	}

	int echo= ( allday+1 ) %7; //每月1号,是星期几

	allday+=day;

	week=allday%7;  //查询星期,是星期几

	printf ( "\n距1900年1月1日: %d天  ",allday-1 );

	if ( ( year%4==0 ) && ( year%100!=0 ) || ( year%400==0 ) )
	printf ( "闰年  \n" );
	else
		printf ( "平年  \n" );

		printf ( "\n%d年 %d月 %d 日  %s\n\n",year,month,day,weeks[week] );


		for ( i=0; i<7; i++ )
		{
			printf ( "%s\t",ss[i] );

			}

	printf ( "\n\n" );

	for ( k=0; k
{
	printf ( "  \t" );
		h++;
	}

	int d;

	for ( d=1; d<=monthday; d++ )
{
	printf ( "%d\t",d );
		h++;
		if ( h>6 )
		{
			h=0;
			printf ( "\n" );
		}

	}


	return 0;
}


网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...