三天打鱼两天晒网
作者:互联网
/*
Date: 11/03/19 11:04
Description: 三天打鱼两天晒网
*/
#include<stdio.h>
int sumDate(int year,int month,int day);
bool judge(int sumday);
bool leap(int year);
int main(void)
{
int year,month,day,sumday;
bool flag;
printf("请输入今天的日期:\n");
scanf("%d%d%d",&year,&month,&day);
sumday=sumDate(year,month,day);
flag=judge(sumday);
if(flag==true)
printf("%d-%d-%d,今天该打鱼!",year,month,day);
else
printf("%d-%d-%d,今天该晒网!",year,month,day);
return 0;
}
bool leap(int year)//该函数用于判断是否为闰年
{
bool lep=false;
if(year%4==0&&year%100!=0||year%400==0)//判断闰年
lep=true;
return lep;
}
int sumDate(int year,int month,int day)//该函数用于求总天数
{
int year1=1990,month1=1,day1=1;//起始年-月-日
int count=0;//统计该年以前闰年年份数
int passday=0;//过去年份的总天数
int nowday=0;//当前年份的总天数
int sumday=0;//统计总天数
int mon[]={31,28,31,30,31,30,31,31,30,31,30,31};//每月对应的天数
for(year1;year1<year;year1++)
{
passday+=365;//每一年先按照365天算
if(leap(year1)==true)
count++;//是闰年count+1
}
passday=passday+count;
printf("前面年份的天数=%d\n",passday);
for(int i=0;i<month-1;i++)
nowday+=mon[i];
nowday=nowday+day;
if(leap(year)==true&&month>=3)
{
nowday+=1;
}
printf("今年的天数=%d\n",nowday);
sumday=passday+nowday;
printf("总天数=%d\n",sumday);
return sumday;
}
bool judge(int sumday)//该函数用于判断打鱼还是晒网
{
bool flag;
switch(sumday%5)
{
case 1://1、2、3天打鱼flag置为true
case 2:
case 3:
flag=true; break;
case 0://4、5天晒网flag置为false
case 4:
flag=false; break;
default: break;
}
return flag;
}
【运行结果】
标签:三天打鱼,两天晒网,int,sumday,month,flag,year,day 来源: https://www.cnblogs.com/sinlearn/p/10510083.html