中国有句俗语叫“三天打鱼两天晒网”,某人从90年1月1日起开始“三天打鱼两天晒网”。问这个人在以后的某一天中是在“打渔”,还是在“晒网”. **输入格式要求:“%d%d%d“ 提示信息:“Enter

中国有句俗语叫“三天打鱼两天晒网”,某人从90年1月1日起开始“三天打鱼两天晒网”。问这个人在以后的某一天中是在“打渔”,还是在“晒网”.
**输入格式要求:"%d%d%d" 提示信息:“Enter year/month/day:”
**输出格式要求:“He is fishing.\n” “He is sleeping.\n”
程序运行示例如下:
Enter year/month/day:1990 1 5
He is sleeping.

答案:

#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
struct date
{
    
    
	int year;
	int month;
	int day;
};
int Month[12] = {
    
     31,28,31,30,31,30,31,31,30,31,30,31 };
int year_day(int year)               //函数功能---返回该年的天数
{
    
    
	if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
	{
    
    
		return 366;
	}
	return 365;
}
int days(int year, int month, int day)     //函数功能--计算输入日期与1990年1月1日的相隔天数
{
    
    
	int t = 0, i;
	for (i = 1990; i < year; i++)    //循环计算输入年份之前所有年份的天数
	{
    
    
		t += year_day(i);
	}
	//下面计算输入年份当年的天数
	for (i = 0; i < month - 1; i++)   
	{
    
    
		t += Month[i];
	}
	t += day;
	if (year_day(year) == 366 && month > 2)
		t++;
	return t;
}
int fish(int t)   //函数功能--打印结果
{
    
    
	if (t % 5 == 4 || t % 5 == 0)
	{
    
    
		printf("He is sleeping.\n");
	}
	else
		printf("He is fishing.\n");
}
int main()
{
    
    
	struct date t;
	printf("Enter year/month/day:");
	scanf("%d %d %d", &t.year, &t.month, &t.day);
	int n = days(t.year, t.month, t.day);
	fish(n);

}

猜你喜欢

转载自blog.csdn.net/qq_52698632/article/details/113597077