请看看这个程式
#include "stdio.h"extern yearday(int year,int month,int day);
int monthday[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}};
main()
{
int y,m,d;
printf("please give year:");
scanf("%d \ n",&y);
printf("please give month:");
scanf("%d \ n",&m);
printf("please give day:");
scanf("%d \ n",&d);
printf("The day of the year is = %d.",yearday(y,m,d));
getch();
}
int yearday(int year,int month,int day)
{
int i,leap;
leap = year%4 == 0 && year%100 !=0 || year%400==0;
for(i=1;i<month;i++)
day+=monthday[leap][i];
return(day);
}
编译成功,运行不对,请各位帮忙也测试一下。
[[italic] 本帖最后由 stevending 于 2007-11-28 22:14 编辑 [/italic]]
搜索更多相关的解决方案:
程式
----------------解决方案--------------------------------------------------------
不明白你的题要做什么~并且有两个地方看的不是很清楚~extern yearday(int year,int month,int day);用extern 定义是什么意思~
leap = year%4 == 0 && year%100 !=0 || year%400==0;
放在这里有什么用~又没括号~也没if语句~
----------------解决方案--------------------------------------------------------
谢谢关注,搞定了
去掉scanf语句中的 n就OK了, 这是一个输入年月日,计算这一天是这一年的第多少天的小程序。 ----------------解决方案--------------------------------------------------------
你说的那一句是求其是否为闰年的公式,运算符号有优先级别,故无需加括号区隔开。
----------------解决方案--------------------------------------------------------
/* 输入:年、月、日,输出该年过去了几天 */
#include<stdio.h>
int main(void)
{
int year, month, day, ndays, i;
int ds[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
printf("Please input year, month, day: ");
while(scanf("%d %d %d", &year, &month, &day) == 3)
{
while(getchar() != '\n');
if(year % 4 == 0)
ds[1] == 29;
else
ds[2] == 28;
if(year < 0 || month < 1 || month > 12 || day > ds[month - 1])
{
printf("Error!\n\nPlease input year,month,day: ");
continue;
}
for(i = ndays = 0; i < month - 1; i++)
ndays += ds[i];
ndays += day;
printf(" : %d\n\n", ndays);
printf("Please input year, month, day: ");
}
puts("Done.");
return 0;
}
/****************************************
我的COS-DOS,账号怎么不能发帖
****************************************/
----------------解决方案--------------------------------------------------------