三天打鱼两天晒网
/*
Date: 11/03/19 11:04
Description: 三天打鱼两天晒网
*/
1 #include<stdio.h> 2 3 int sumDate(int year,int month,int day); 4 bool judge(int sumday); 5 bool leap(int year); 6 7 int main(void) 8 { 9 int year,month,day,sumday; 10 bool flag; 11 12 printf("请输入今天的日期:\n"); 13 scanf("%d%d%d",&year,&month,&day); 14 sumday=sumDate(year,month,day); 15 flag=judge(sumday); 16 if(flag==true) 17 printf("%d-%d-%d,今天该打鱼!",year,month,day); 18 else 19 printf("%d-%d-%d,今天该晒网!",year,month,day); 20 21 return 0; 22 } 23 bool leap(int year)//该函数用于判断是否为闰年 24 { 25 bool lep=false; 26 if(year%4==0&&year%100!=0||year%400==0)//判断闰年 27 lep=true; 28 return lep; 29 } 30 int sumDate(int year,int month,int day)//该函数用于求总天数 31 { 32 int year1=1990,month1=1,day1=1;//起始年-月-日 33 int count=0;//统计该年以前闰年年份数 34 int passday=0;//过去年份的总天数 35 int nowday=0;//当前年份的总天数 36 int sumday=0;//统计总天数 37 int mon[]={31,28,31,30,31,30,31,31,30,31,30,31};//每月对应的天数 38 39 for(year1;year1<year;year1++) 40 { 41 passday+=365;//每一年先按照365天算 42 if(leap(year1)==true) 43 count++;//是闰年count+1 44 } 45 passday=passday+count; 46 printf("前面年份的天数=%d\n",passday); 47 48 for(int i=0;i<month-1;i++) 49 nowday+=mon[i]; 50 nowday=nowday+day; 51 if(leap(year)==true&&month>=3) 52 { 53 nowday+=1; 54 } 55 printf("今年的天数=%d\n",nowday); 56 sumday=passday+nowday; 57 printf("总天数=%d\n",sumday); 58 return sumday; 59 } 60 bool judge(int sumday)//该函数用于判断打鱼还是晒网 61 { 62 bool flag; 63 switch(sumday%5) 64 { 65 case 1://1、2、3天打鱼flag置为true 66 case 2: 67 case 3: 68 flag=true; break; 69 case 0://4、5天晒网flag置为false 70 case 4: 71 flag=false; break; 72 default: break; 73 } 74 return flag; 75 }
【运行结果】