我们在学习上三天打鱼两天晒网可是不行的,而当我们把三天打鱼两天晒网变成题目来求某人在某一天当中是打鱼还是晒网要如何来解呢。题目:中国有句俗语叫“三天打鱼两天晒网”。某人从1990年1月1日起开始“三天打鱼两天晒网”,问这个人在以后的某一天中是“打鱼”还是“晒网”。
.程序源代码:
#include
/*定义日期结构体*/
typedef struct date {
int year;
int month;
int day;
}date;
int countday(date currentday); /*函数声明*/
int runyear(int year); /*函数声明*/
int main()
{
date today; /*指定日期*/
int totalday; /*指定日期距离1990年1月1日的天数*/
int result; /*totalday对5取余的结果*/
/*输入指定日期,包括年,月,日*/
printf(please input 指定日期包括年,月,日 如:1999 1 31\n);
scanf(%d%d%d, &today.year, &today.month, &today.day);
totalday=countday(today); /*求出指定日期距离1990年1月1日的天数*/
/*天数%5,判断输出打鱼还是晒网*/
result=totalday%5;
if(result>0 && result<4)
printf(今天打鱼);
else
printf(今天晒网);
return 0;
}
/*判断是否为闰年,是返回1,否返回0*/
int runyear(int year)
{
if( (year%4==0 && year%100!=0) || (year%400==0) ) /*是闰年*/
return 1;
else
return 0;
}
/*计算指定日期距离1990年1月1日的天数*/
int countday(date currentday)
{
int permonth[13]={0,31,28,31,30,31,30,31,31,30,31,30}; /*每月天数数组*/
int totalday=0,year,i;
/*求出指定日期之前的每一年的天数累加和*/
for(year=1990; year
{
if(runyear(year)) /*判断是否为闰年*/
totalday=totalday+366;
else
totalday=totalday+365;
}
/*如果为闰年,则二月份为29天*/
if(runyear(currentday.year))
permonth[2]+=1;
/*将本年内的天数累加到totalday中*/
for(i=0; i
totalday+=permonth[i];
/*将本月内的天数累加到totalday中*/
totalday+=currentday.day;
/*返回totalday*/
return totalday;
}
本文转载自长沙尚学堂http://www.cssxt.com/ranjianpx/10614.html,网站内还有名师高淇、马士兵零基础自学java视频下载哦
北京尚学堂科技有限公司湖南分公司
0731 83072091