设一月一号为第一天,计算某月的某一天,是在打鱼还是在晒网?
#include<stdio.h>
main()
{
int mm,dd,i,len,ch=0,sh,a;//定义变量
printf("请输入日期:\n");
scanf("%d-%d",&mm,&dd);//对变量进行赋值,mm为所计算的月份,dd为日份
for(i=0;i<mm;i++)
{
switch(i)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:len=31;break;
case 4:
case 6:
case 9:
case 11:len=30;break;
case 0:len=0;break;
case 2:
if(2020%4==0&&2020%100!=0||2020%400==0)//判断是平年还是闰年以确定二月的天数
len=29;
else
len=28;
}
ch=ch+len;
}
sh=ch+dd;//从一月一号至当日所经过的天数
a=sh%5;//判断是五天中的哪一天
if(a>0&&a<=3)
printf("he is fishing!\n");//输出判断结果
else
printf("he is dring nets!\n");//输出判断结果
}