- 1、本文档共13页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
三天打鱼两天筛网
/*三天打鱼两天晒网*
#include stdio.htypedef struct date{int year;int month;int day;}Date;int dayFunc (Date term);int main(){Date today, term;int yearday, year, day;printf(Enter year/month/day:);scanf(%d/%d/%d,today.year,today.month,today.day);/*初始值*/term.month = 12;term.day = 0;for (yearday=0, year=1990;yeartoday.year;year++){term.year = year;yearday += dayFunc(term);/*到指定年的前一年共天数*/}yearday += dayFunc(today);/*加上当年天数*/printf(total days is %d\n,yearday);day = yearday%5;if (day0 day4)printf(He was fishing.\n);elseprintf(He was sleeping.\n);return 0;}int dayFunc (Date term){static int day_tab[2][12] = {{31,28,31,30,31,30,31,31,30,31,30,31}, {31,29,31,30,31,30,31,31,30,31,30,31}};int i,Isrunian;/*是否为润年*/Isrunian = (term.year%4 == 0)(term.year%100!=0) || (term.year%400 == 0);for (i=1;iterm.month;i++)term.day += day_tab[Isrunian][i-1];/*注意i-1*/return term.day;}
某人自2000年1月1日起三天打鱼两天晒网。任意输入一个日期,问其是打鱼还是晒网?要求考虑闰年和不同月份不同#include stdio.h#define YEAR 2000#define DAYS 365int TotalDays(int year,int month,int day);int a[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};int main(){ int totalday; int year,month,day; printf(please input the yaer-month-day:); scanf(%d-%d-%d,year,month,day); totalday = TotalDays(year,month,day); printf(%d-%d-%d 是:,year,month,day); if (totalday % 5 == 0 || totalday % 5 == 4) { printf(晒网日!\n); } else { printf(打鱼日!\n); } return 0;}//统计当前的天数int TotalDays(int year,int month,int day){ int i = year - YEAR; int i_month = 1; int totalday = day; if ( year%4 == 0 year%100 != 0) { a[2] = 29; } while (i_month month) { totalday += a[i_month ++]; //这句没看懂,求解释 } if ( i 0 ) { totalday += DAYS*i + (i-1)/4 + 1;//这句没看懂,求解释,为什么 (i-1)/4 + 1;??? } return totalday;}
#include stdio.h#define YEAR 2000#define DAYS 365int TotalDays(int year,int month,int day);int a[] = {0,
文档评论(0)