结构体题
定义一个结构体变量,计算该日在本年中是第几天,并且主函数将年,月,日传递给函数,计算后再将结果传回给主函数并输出.
#include<stdio.h>
struct date
{
int year;
int month;
int day;
};
int fun(date);
void main()
{
date a={1997,2,1};//可以加输入语句自己赋值
printf(\"There are %d days till %d月%d号\n\",fun(a)+a.day,a.month,a.day);
}int fun(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;
}