这个问题很简单呀!
年对四求余!!!!!!确定2月的值!!!!!!!!
对月的值进行判断!!!!!!!!!分出大月,月,2月(小月)
在用循环加
最后加上日!!!!!!!!!
就OK了
是不是很简单呀!!!!!!!!!!!!1
int i,days=0;
int p[12]={31,28,31,30,31,30,31,31,30,31,30,31}
if(闰年) p[1]++;
for(i=0;i<月份数;i++) days+=p[i];
printf("%d",days+天数);
闰年判断方法楼上已写,如不懂跟帖提问,闰年判断最好通过函数(这样结构化思想强,利于读懂程序),月份数与天数通过scanf读取,这是最基本的了,写好scanf后将读入数据的变量名替换这些文字就是纯C语言程序了
[此贴子已经被作者于2006-11-30 20:09:18编辑过]
这段代码还需要修改:
在scanf("%d,%d,%d",&year,&month,&day);前要加上i=0;
既: ……
printf("input the year,month and day:\n");
{
i=0; // must add
scanf("%d,%d,%d",&year,&month,&day);
if(month<=0||month>12)
……
另外有一处笔误:while(1);应为while(i);
#include<stdio.h>
struct date
{
int year;
int month;
int day;
}a;
int fun(struct 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;
}
#include<stdio.h>
struct date
{
int year;
int month;
int day;
}a;
int fun(struct 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 你太强了,有机会指点指点一下小弟。
其中有一点我不太明白,
while(printf("input the data(year/month/day):"),scanf("%d/%d/%d",&a.year,&a.month,&a.day))
是怎么判断的。谢谢!
请问你的联系方式,我要向你请教很多问题。