#include"stdio.h"
struct ymd
{
int year;
int month;
int day;
};
int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int days(struct ymd *p)
{
int i,d=p->day;
if(p->year%4==0&&p->year%100!=0||p->year%400==0)
day[2]=29;
for(i=1;1<p->month;i++)
d=d+day[i];
return d;
}
void main()
{
struct ymd date;
printf("输入年份:");
scanf("%d",&date.year);
printf("输入月份:");
scanf("%d",&date.month);
printf("输入日期:");
scanf("%d",&date.day);
int d=days(&date);
printf("\n该天在本年的第%d天",d);
}
程序如上,但是输入数据后无法运行
for(i=1;1<p->month;i++)
d=d+day[i];
这里应该是
for(i=1;i<p->month;i++)
d=d+day[i];
#include"stdio.h"
struct ymd
{
int year;
int month;
int day;
};
int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int days(struct ymd *p)
{
int i,d=p->day;
if(p->year%4==0&&p->year%100!=0||p->year%400==0)
day[2]=29;
for(i=1;i<p->month;i++)//这里把i写成了1真无语了
d=d+day[i];
return d;
}
void main()
{
struct ymd date;
printf("输入年份:");
scanf("%d",&date.year);
printf("输入月份:");
scanf("%d",&date.month);
printf("输入日期:");
scanf("%d",&date.day);
int d=days(&date);
printf("\n该天在本年的第%d天",d);
}