万年历程序设计c语言代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

这是当时我做的一个小小的课题,希望对你有所帮助

#include "stdio.h" /* Required for MS-DOS use */

#define ENTER 0x1C0D /* Enter key */

int year, month, day;

static char *days[8] = {" ","Sunday ","Monday ","Tuesday ",

"Wednesday","Thursday ","Friday ","Saturday "}; struct TIMEDATE {

int year; /* year 1980..2099 */

int month; /* month 1=Jan 2=Feb, etc. */

int day; /* day of month 0..31 */

int hours; /* hour 0..23 */

int minutes; /* minute 0..59 */

int seconds; /* second 0..59 */

int hsecs; /* 1/100ths of second 0..99 */

char dateline[47]; /* date & time together */

};

static struct TIMEDATE today;

main()

{

char cmonth[3];

char cday[3];

char cyear[5];

double getdays();

double daynumb, numbnow;

int weekday, retcode, dayer, i;

dayer = datetime(&today);

clrscn();

for (i=0;i<3;++i)cmonth[i]='\0';

for (i=0;i<3;++i)cday[i]='\0';

for (i=0;i<5;++i)cyear[i]='\0';

putstr(5,8,14,"Enter date in MM DD YYYY format:");

while (retcode != ENTER)

{

retcode = bufinp(5,41,13,2,cmonth);

if (retcode != ENTER) retcode = bufinp(5,44,13,2,cday);

if (retcode != ENTER) retcode = bufinp(5,47,13,4,cyear);

}

year = atoi(&cyear);

month = atoi(&cmonth);

day = atoi(&cday);

daynumb = getdays(year, month, day);

numbnow = getdays(today.year, today.month, today.day); weekday = weekdays(daynumb);

if (numbnow - daynumb == 0)

printf("\n\n%02d-%02d-%d is",month, day, year);

if (numbnow - daynumb > 0)

printf("\n\n%02d-%02d-%d was",month, day, year);

if (numbnow - daynumb < 0)

printf("\n\n%02d-%02d-%d will be",month, day, year);

printf(" a %s\n",days[weekday]);

} /* end MAIN */

/************************************************************

* GETDAYS - From integer values of year (YYYY), month * * (MM) and day (DD) this subroutine returns a *

* double float number which represents the * * number of days since Jan 1, 1980 (day 1). * * This routine is the opposite of GETDATE. * ************************************************************/

double getdays(year, month, day)

int year, month, day;

{

int y,m;

double a,b,d, daynumb;

double floor(),intg();

/**********************************

** make correction for no year 0 **

**********************************/

if (year < 0) y = year + 1;

else y = year;

/*********************************************************

** Jan and Feb are months 13 and 14 in this calculation **

*********************************************************/

m = month;

if (month < 3)

{

m = m + 12;

y = y - 1;

}

/**************************

** calculate Julian days **

**************************/

d = floor(365.25 * y) + intg(30.6001 * (m + 1)) + day - 723244.0;

/**********************************************

相关文档
最新文档