| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 416 人关注过本帖
标题:学习C语言中遇到一个不解的问题
只看楼主 加入收藏
jstxlwl118
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2007-6-1
收藏
 问题点数:0 回复次数:0 
学习C语言中遇到一个不解的问题

我先上传两个程序:

第一個:

/*通过输入当天的日期算出第二天的日期*/
#include "Stdio.h"

struct date
{ int day;
int month;
int year;
};
int main(void) //主程序
{
struct date today,tomorrow;
int chazhao(struct date d);
int ruinian(struct date x);
struct date update(struct date d);

printf ("pleae input today's date(mm/dd/yyyy): ");
scanf ("%i%i%i",&today.month,&today.day,&today.year);

tomorrow=update(today);

printf ("next date is %i/%i/%i\n",tomorrow.month,tomorrow.day,tomorrow.year);


getch();

}

int chazhao(struct date d) //查找月分的天数
{ const int endday[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int days;

if ( ruinian(d)==1&&d.month==2)
days=29;
else
days=endday[d.month-1];

return days;
}
int ruinian(struct date x) //是否为润年
{ int t;
if ((x.year%4==0&&x.year%100!=0)||x.year%400==0)
t=1;
else t=-1;

return t;
}

struct date update(struct date d) //第二天的日期
{ struct date next;
if (d.day!=chazhao(d))
{next.day=d.day+1;
next.month=d.month;
next.year=d.year;
}
else if (d.month==12)
{next.day=1;
next.month=1;
next.year=d.year+1;
}

else
{next.day=1;
next.month=d.month+1;
next.year=d.year;
}

return next;
}



第二個:



/*通过输入当天日期算出第二天的日期*/
#include "Stdio.h"

struct date
{ int day;
int month;
int year;
};
int main(void) /*主程序*/
{
struct date today,tomorrow;
int chazhao(struct date d);
int ruinian(struct date x);
struct date update(struct date d);

printf ("pleae input today's date(mm/dd/yyyy): ");
scanf ("%i%i%i",&today.month,&today.day,&today.year);

tomorrow=update(today);

printf ("next date is %i/%i/%i\n",tomorrow.month,tomorrow.day,tomorrow.year);


getch();

}

int chazhao(struct date d) /*查找月分的天数*/
{ const int endday[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int days;

if ( ruinian(d)==1&&d.month==2)
days=29;
else
days=endday[d.month-1];

return days;
}
int ruinian(struct date x) /*是否为润年*/
{ int t;
if ((x.year%4==0&&x.year%100!=0)||x.year%400==0)
t=1;
else t=-1;

return t;
}

struct date update(struct date d) /*利用复合字面量计算第二天的日期*/
{ struct date next;
if (d.day!=chazhao(d))
next=(struct date){d.day+1,d.month,d.year};
else if (d.month==12)
next=(struct date){1,1,d.year+1};
else
next=(struct date){1,d.month+1,d.year};


return next;
}


以上两个程序功能是一样的。。大家看我用红字标出来的地方。。我是根据书上写的。为什么有错误呀,书上写的是可以使用复合字面量呀。。

大家幫幫我呀。。到底怎麽回事呀

[此贴子已经被作者于2007-7-15 22:29:18编辑过]

搜索更多相关主题的帖子: C语言 学习 
2007-07-15 22:27
快速回复:学习C语言中遇到一个不解的问题
数据加载中...
 
   



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

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