| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5411 人关注过本帖
标题:输入年月日输出第几天
只看楼主 加入收藏
月之神
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-10-26
收藏
 问题点数:0 回复次数:15 
输入年月日输出第几天

怎么要求输入年月日输出地几天还差什么????????
(Y年 M月 D天)
#include<stdio.h>
int month[12]={31,28,31,30,31,30,31,31,30,31,30,31} ;
int main()
{
int Y,M,D,i,total;
scanf("%d %d %d",&Y,&M,&D);
if(Y%4!=0&&Y%100==!0)
for (i=0;i<=M-1;i++)
total=month[i]+month[i-1]+D;
else if((Y%4==0&&Y%100==0)||Y%400==0)
{
if(M==1)
printf("total=%d",total);
if(M==2)
total=31+D;
printf("total=%d",total) ;
if(M>=3)
for(i=3;i<=M-1;i++)
total=month[0]+month[1]+month[i-1]+D+1;
printf("total=%d",total);
}
getch ();
return 0;
}

搜索更多相关主题的帖子: 年月日 输出 输入 
2006-11-11 21:37
ziyi555
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2006-11-4
收藏
得分:0 

有个重要问题
输入的年月日需要判断是否合法 比如输入了13月
或者 2月份出了30天 或者4月分出了31天都是不正确的
需要判断一下


放手一博
2006-11-12 11:31
guzhou
Rank: 1
等 级:新手上路
威 望:1
帖 子:247
专家分:0
注 册:2006-11-4
收藏
得分:0 
以下是引用月之神在2006-11-11 21:37:19的发言:

怎么要求输入年月日输出地几天还差什么????????
(Y年 M月 D天)
#include<stdio.h>
int month[12]={31,28,31,30,31,30,31,31,30,31,30,31} ;
int main()
{
int Y,M,D,i,total=0;
scanf("%d %d %d",&Y,&M,&D);
if(Y%4!=0&&Y%100==!0) //这里多余
for (i=0;i<=M-1;i++) //M-2
total=month[i]+month[i-1]+D; //?? {total=total+mounth[i];total=total+D;}
else if((Y%4==0&&Y%100==0)||Y%400==0) //Y%100!=0
{
if(M==1)
printf("total=%d",total); //应为D
if(M==2)
total=31+D;
printf("total=%d",total) ;
if(M>=3)
for(i=3;i<=M-1;i++) i=2
total=month[0]+month[1]+month[i-1]+D+1;
//这里同上最后+1即可.
printf("total=%d",total);
}
getch ();
return 0;
}


2006-11-12 13:16
月之神
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-10-26
收藏
得分:0 
我去试试
谢谢
2006-11-12 19:44
guzhou
Rank: 1
等 级:新手上路
威 望:1
帖 子:247
专家分:0
注 册:2006-11-4
收藏
得分:0 
不好意思有点小错,
else后应为

else if((Y%4==0&&Y%100!==0)||Y%400==0)
{
mouth[1]=29;
for (i=0;i<=M-2;i++)
{
total=total+mounth[i];
total=total+D;
}
printf("total=%d",total);
}

2006-11-13 15:29
月之神
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-10-26
收藏
得分:0 
还是不对啊
2006-11-13 22:08
wuxilyy1
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2006-11-5
收藏
得分:0 

在系统的库函数里面可以读取2个系统时间,然后计算其差值的,得到的结果可能是精确到秒的.
是否可以将需要计算的2个时间输入(XXXX年XX月X日0时0分0秒),计算其差值后直接除以86400.

2006-11-15 23:18
unicorn
Rank: 4
等 级:贵宾
威 望:14
帖 子:1066
专家分:0
注 册:2005-10-25
收藏
得分:0 

注意润年
统计你输入的日子到1月1号的天数就行了

#include<stdio.h>
struct date
{
int year;
int month;
int day;
}a;
int fun(date);
void main()
{
while(printf(\"input the data(year/month/day):\"),scanf(\"%d/%d/%d\",&a.year,&a.month,&a.day))
printf(\"There are %d days\n\",fun(a)+a.day);
}

int fun(struct date a)
{
int leap=0,sum=0;
int num[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}};
if((a.year%4==0&&a.year%100!=0)||a.year%400==0) leap=1;
for(int i=0;i<a.month;i++) sum+=num[leap][i];
return sum;
}



unicorn-h.spaces. ◇◆ sava-scratch.spaces.  noh enol ! pue pu!w hw u! shemle aq ll!m noh 
2006-11-16 10:30
cailong103
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-11-16
收藏
得分:0 
我的可以
#include<stdio.h>
int month[12]={31,28,31,30,31,30,31,31,30,31,30,31} ;
main()
{
int Y,M,D,i,total=0;
scanf("%d %d %d",&Y,&M,&D);
if(Y%4!=0)
{
if(M==1)
total=D;
else
for (i=0;i<=M-2;i++)
total+=month[i]+D;
}
else
{
if(M==1)
total=D;
else if(M==2)
total=31+D;
else if(M>=3)
{for(i=2;i<=M-2;i++)
total+=month[0]+month[i-1]+D+1;}
}
printf("total=%d",total);
}
2006-11-16 15:05
cailong103
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-11-16
收藏
得分:0 
发错了
#include<stdio.h>
int month[12]={31,28,31,30,31,30,31,31,30,31,30,31} ;
main()
{
int Y,M,D,i,total=0;
scanf("%d %d %d",&Y,&M,&D);
if(Y%4!=0)
{
if(M==1)
total=D;
else
for (i=0;i<=M-2;i++)
total+=month[i];
total+=D;
}
else
{
if(M==1)
total=D;
else if(M==2)
total=31+D;
else if(M>=3)
{for(i=2;i<=M-2;i++)
total+=month[i-1];
total+=month[0]+D+1;}
}
printf("\ntotal=%d\n",total);
}
2006-11-16 15:07
快速回复:输入年月日输出第几天
数据加载中...
 
   



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

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