(1)定义一个结构体变量(包括年,月,日).计算该日在本年中是第几天?用函数及返回值形式完成。
#include "stdio.h"
int calculate(int a);
void main()
{
printf("Please input the day(XXXX/XX/XX):\n");
printf("\nThe day is the %dth day.\n",calculate(a));
}
int calculate(int a)
{ struct date
{ int year,month,day;}aday;
int i,n=0;
scanf("%d/%d/%d",&aday.year,&aday.month,&aday.day);
for(i=1;i<aday.month;i++)
ffffffffffffffffffffffff
switch(i)
{ case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:n+=31;break;
case 4:
case 6:
case 9:
case 11:n+=30;break;
case 2:if(aday.year%4==0&&aday.year%100!=0||aday.year%400==0)
n+=29;
else
n+=28;
}
n+=aday.day;
a=n;
return a;
} 展开
#include "stdio.h"
int calculate();//没传递参数
int main()
{
printf("Please input the day(XXXX/XX/XX):\n");
printf("\nThe day is the %dth day.\n",calculate());
}
int calculate()
{
struct date
{
int year,month,day;
} aday;
int i,n=0;
scanf("%d/%d/%d",&aday.year,&aday.month,&aday.day);
for(i=1;i<aday.month;i++)
switch(i)
{ case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:n+=31;break;
case 4:
case 6:
case 9:
case 11:n+=30;break;
case 2:if(aday.year%4==0&&aday.year%100!=0||aday.year%400==0)
n+=29;
else
n+=28;
}
n+=aday.day;
return n;
}