标题:[求助]:天数与日期的转换问题,小弟新手!
只看楼主
李飞龙
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-9-18
 问题点数:0 回复次数:4 
[求助]:天数与日期的转换问题,小弟新手!

*/ --------------------------------------------------------------------------------------
*/ 出自: 编程中国 http://www.bc-cn.net
*/ 作者: 李飞龙 QQ:81516156
*/ 时间: 2007-9-18 编程论坛首发
*/ 声明: 尊重作者劳动,转载请保留本段文字
*/ --------------------------------------------------------------------------------------
main()
{static int day_tab[][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}};
printf("%d\n",day_of_year(day_tab,2007,100));
}
day_of_year(day_tab,year,yearday,pmonth,pday)
int year,yearday,*pmonth,*pday;
{
int i,leap,q;
leap=(year%4==0&&year%100||year%400==0);
for(i=1;yearday>(q=*(*(day_tab+leap)+i));i++)
yearday-=q;
*pmonth=i;
*pday=yearday;
}



实在不知道哪儿错了?
望大侠指导一下!!!

搜索更多相关主题的帖子: 天数 
2007-09-18 16:55
wangmingqun
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2007-10-23
得分:0 

void main()
{
static int day_tab[][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}};
printf("%d\n",day_of_year(day_tab,2007,100));///////////
}

int day_of_year(day_tab,year,yearday,pmonth,pday)////////////
int year,yearday,*pmonth,*pday;
{
int i,leap,q;
leap=(year%4==0&&year%100||year%400==0);
for(i=1;yearday>(q=*(*(day_tab+leap)+i));i++)
yearday-=q;
*pmonth=i;
*pday=yearday;
}

你的函数调用的都不正确啊。还有就是你以后写程序请注意自己程序的清晰。

2007-11-06 10:39
LOvE老鼠YoU
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2007-11-5
得分:0 

请问这些东西
void main()
{
static int day_tab[][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}};
printf("%d\n",day_of_year(day_tab,2007,100));///////////
}

int day_of_year(day_tab,year,yearday,pmonth,pday)////////////
int year,yearday,*pmonth,*pday;
{
int i,leap,q;
leap=(year%4==0&&year%100||year%400==0);
for(i=1;yearday>(q=*(*(day_tab+leap)+i));i++)
yearday-=q;
*pmonth=i;
*pday=yearday;
都是要用手写打出来吗?
小弟新手

2007-11-06 11:51
BTMouse
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2007-8-23
得分:0 

的确这格式看都看不懂,应该改正确了在发上来。{}匹配都不对嘛

2007-11-06 13:38
静思
Rank: 3Rank: 3
来 自:沈阳
等 级:新手上路
威 望:8
帖 子:630
专家分:0
注 册:2006-2-28
得分:0 

楼主错误好多,在主函数中应声明两个指针,分别存放月份和当月的天数,函数返回时得到相应的月数和天数
主函数:
static int day_tab[][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 main()
{

int *p_month,*p_day;
void day_of_year(int,int,int *,int *);
p_month=new (int);
p_day=new (int);
day_of_year(2007,100,p_month,p_day);
printf("%d月 %d日\n",*p_month,*p_day);
delete p_day;
delete p_month;
return 0;
}
void day_of_year(int year,int yearday,int *pmonth,int *pday)
{
int i,leap,q;
leap=(year%4==0&&year%100||year%400==0);
for(i=1;yearday>(q=*(*(day_tab+leap)+i));i++)
yearday-=q;
*pmonth=i;
*pday=yearday;
}


英者自知,雄者自胜
2007-11-06 14:22



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




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

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