定义一个结构体变量(包括年、月、日),要求输入年月日,编写程序计算并输出该日在本年中第几天.

2024-12-15 15:48:08
推荐回答(2个)
回答1:

// 现写的!

#include
#include
#define TRUE 1
#define FALSE 0
typedef int BOOL;

int YearMouth[]={31,29,31,30,31,30,31,31,30,31,30,31,32};

typedef struct Date
{
int year;
int mouth;
int day;
}DATE;

//判断是否是瑞年
BOOL isNotRuiYear(int year)
{
BOOL flog=FALSE;

if(0==year%4 && 0==year/4%100)
flog=TRUE;
if(0==year%400)
flog=TRUE;

return flog;
}

void main()
{

DATE date;
int i;
int AllDay=0;
//提示输入年月日
printf("please input int year!\n");
scanf("%d",&date.year);
printf("please input int mouth!\n");
scanf("%d",&date.mouth);
printf("please input int day!\n");
scanf("%d",&date.day);
//计算天数
if(isNotRuiYear(date.year))
{
for(i=0;i AllDay+=YearMouth[i];
AllDay-=1;
}
else
{
for(i=0;i
}
//打印结果
printf("this %d year %d mouth %d day in all year is %d days \n",date.year,date.mouth,date.day,AllDay);

}

回答2:

#include
void main()
{
struct date{
int year;
int month[12];
int day;
}_date={0,{31,28,31,30,31,30,31,31,30,31,30,31},0};
int mon,i,days=0;
scanf("%d%d%d",&_date.year,&mon,&_date.day);
if((!(_date.year%4)&&_date.year%100)||!(_date.year%400))
_date.month[1]=29;
for(i=0;i days+=_date.month[i];
days+=_date.day;
printf("%d\n",days);
}
我们的作业……