标题:请教大侠C语言问题,不胜感激
只看楼主
edis123
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-2-18
 问题点数:0 回复次数:4 
请教大侠C语言问题,不胜感激
小弟刚接触C语言不久,这是“三天打鱼,两天嗮网”的程序,但是不知道为什么运行不出来?还请大侠指点如何修改?谢谢。。。
#include"stdio.h"
struct date{
    int year ;
    int month;
    int day;
};
days(day)
struct date day;
{
static int day_tab[2][13]=
    {{0,31,28,31,30,31,30,31,30,31,30,31,30,31,},
     {0,31,29,31,30,31,30,31,30,31,30,31,30,31,},
    };
    int lp,i;
    lp=day.year%4==0 && day.year%100!=0 || day.year%400==0;
    for(i=1;i<=day.month;i++)
        day.day+=day_tab[lp][i];
    return(day.day);
   
}
main()
{
    struct date today,term;
    int yearday,year,day;
    printf("input year/month/day\n");
    scanf("%d%d%d\n",&today.year,&today.month,&today.day);
    term.month=12;
    term.day=31;
    for(yearday=0,year=1990;year<today.year;year++)
    {
        term.year=year;
        yearday+=days(term);
    }
    yearday+=days(today);
    day=yearday%5;
    if (day>0 && day<4)
        printf("fishing day\n");
    else
        printf("sleeping day\n");
}



搜索更多相关主题的帖子: 400 不胜感激 include C语言 
2012-02-18 19:45
weipeng1217
Rank: 5Rank: 5
等 级:职业侠客
帖 子:175
专家分:386
注 册:2012-1-12
得分:0 
这程序有啥用?

C坛友交流群 群号:161091913 ,欢迎经常在线的朋友加入,一起学习,一起进步。。
2012-02-18 19:51
edis123
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-2-18
得分:0 
回复 2楼 weipeng1217
计算哪天打鱼,哪天嗮网的程序,但是运行有bug。。。。
2012-02-19 09:08
enjoy迷星
Rank: 2
等 级:论坛游民
帖 子:18
专家分:42
注 册:2011-11-5
得分:0 
#include"stdio.h"
struct date{
    int year ;
    int month;
    int day;
};
days(date day)       //形参同时声明类型
//date day;
{
static int day_tab[2][13]=
    {{0,31,28,31,30,31,30,31,31,30,31,30,31},    //你的月数不对,而且每月的天数不对,要细心!
     {0,31,29,31,30,31,30,31,31,30,31,30,31},
    };
    int lp,i;
    lp=day.year%4==0 && day.year%100!=0 || day.year%400==0;
    for(i=1;i<=day.month;i++)
        day.day+=day_tab[lp][i];
    return(day.day);
   
}
void main()    //无返回值时函数要声明为void
{
    struct date today,term;
    int yearday,year,day;
    printf("input year/month/day\n");
    scanf("%d%d%d\n",&today.year,&today.month,&today.day);
    term.month=12;
    term.day=31;
    for(yearday=0,year=1990;year<today.year;year++)
    {
        term.year=year;
        yearday+=days(term);
    }
    yearday+=days(today);
    day=yearday%5;
    if (day>0 && day<4)
        printf("fishing day\n");
    else
        printf("sleeping day\n");
}
2012-02-19 12:56
edis123
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-2-18
得分:0 
回复 4楼 enjoy迷星
谢谢~~
2012-02-19 13:47



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-361139-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.441767 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved