| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 349 人关注过本帖
标题:求助
只看楼主 加入收藏
qidaovb
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2007-7-25
收藏
 问题点数:0 回复次数:4 
求助
给定年月日,求其为一年的第N天:
以下是我的程序,系统报错,我实在找不出了,求助!
#include<stdio.h>
void main()
{
int y,m,d,result,le,i,S[2][13];
printf("please imput the day of year:");
scanf("%d%d%d",y,m,d);
S[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}};
le=((y%4==0&&y%100!=0)||y%400==0);
for(i=0;i<m;i++)
{
result=d+S[le][i];
}
// return re;
printf("result is %d",result);
}
搜索更多相关主题的帖子: void include return result 
2007-09-02 21:42
cordier
Rank: 2
等 级:论坛游民
威 望:1
帖 子:449
专家分:14
注 册:2006-2-9
收藏
得分:0 
#include<stdio.h>
void main()
{
int y,m,d,result,le,i,S[2][13];
printf("please imput the day of year:");
scanf("%d%d%d",y,m,d); /*应当是scanf("%d%d%d",&y,&m,&d);*/
S[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}}; /*数组只能在声明的时候,给所有的元素赋值*/
le=((y%4==0&&y%100!=0)||y%400==0);
for(i=0;i<m;i++)
{
result=d+S[le][i]; /*有问题*/
}
// return re;
printf("result is %d",result);
}


/*稍微改了一些,应当是可以的*/
#include<stdio.h>
void main()
{
int y,m,d,result,le,i,S[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}};
printf("please imput the day of year:");
scanf("%d%d%d",&y,&m,&d);
le=((y%4==0&&y%100!=0)||y%400==0);
result=d;
for(i=0;i<m;i++)
{
result+=S[le][i];
}
printf("result is %d",result);
getch();
}

2007-09-02 21:53
mayi2007
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2007-8-19
收藏
得分:0 
#include<stdio.h>
void main()
{
int y,m,d,result,le,i,S[][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("please imput the day of year:");
scanf("%d%d%d",&y,&m,&d);

if((y%4==0&&y%100!=0)||y%400==0)
le=1;
else
le=0;
result=d;
for(i=0;i<m;i++)
result+=S[le][i];
printf("result is %d",result);
}
2007-09-02 21:55
mayi2007
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2007-8-19
收藏
得分:0 
le=((y%4==0&&y%100!=0)||y%400==0);
这句是什么意思啊...
2007-09-02 21:58
andyzhshg
Rank: 2
等 级:论坛游民
帖 子:111
专家分:20
注 册:2007-9-1
收藏
得分:0 

#include<stdio.h>
void main()
{
int y,m,d,result,le,i,S[2][13];
printf("please imput the day of year:");
scanf("%d%d%d",y,m,d);
S[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}};

le=((y%4==0&&y%100!=0)||y%400==0);
for(i=0;i<m;i++)
{
result=d+S[le][i];
}
// return re;
printf("result is %d",result);
}
scanf的输入格式错误。
除非在定义时就赋值,否则之后是无法这样赋值的。
此处运算式不对
下面是改后的程序
#include<stdio.h>
void main()
{
int y,m,d,result,le,i,S[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}};
printf("please imput the day of year:");
scanf("%d%d%d",&y,&m,&d);

le=((y%4==0&&y%100!=0)||y%400==0);
result = 0;
for(i=0;i<m;i++)
{
result = result + S[le][i];
}
result = result + d;
// return re;
printf("result is %d",result);
}


编程并快乐着
2007-09-02 22:31
快速回复:求助
数据加载中...
 
   



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

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