打鱼还是晒网C语言

来源:互联网 发布:淘宝专享打折怎么设置 编辑:程序博客网 时间:2022/05/28 06:33

某人从1990年1月1日起开始“三天打鱼两天晒网”,问这个人在以后
的某一天中是“打鱼”还是“晒网”?
分析:
1. 计算从1990年1月1日到指定日期总共有多少天
2. 打鱼和晒网的周期为5天,将总天数除以5取余数
3. 余数为1,2,3,则打鱼,否则为晒网

#include<stdio.h>typedef struct date{    int year;    int month;    int day;} DATE; int countDay(DATE); int runYear(int); void main(){    DATE today;    int totalDay;    int result;    printf("please input date like 1998 2 20 \n");    scanf("%d %d %d",&today.year,&today.month,&today.day);    totalDay = countDay(today);    result = totalDay % 5;    if(result>0 && result<4)        printf("今天打鱼");    else        printf("今天晒网"); } //判断是否为闰年int runYear(int year){    if((year%4==0 && year%100!=0) || (year%400==0))        return 1;    else        return 0; } //计算到指定日期的总天数int countDay(DATE currentDay){    int perMonth[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};    int totalDay = 0,year,i;    for(year=1990;year<currentDay.year;year++)    {        if(runYear(year))            totalDay = totalDay + 366;        else            totalDay = totalDay + 365;    }     if(runYear(currentDay.year))        perMonth[2] += 1;    for(i=0;i<currentDay.month;i++)        totalDay += perMonth[i];    totalDay += currentDay.day;     return totalDay;} 
原创粉丝点击