c语言 输入年月日,输出它是本年第几天

#include <stdio.h>


int main()
{
   int year,month,day;//年月日
   int i;
   int sum = 0;//标记天数
   int date[12]={31,29,31,30,31,30,31,31,30,31,30,31};
   printf("输入年月日:");
   scanf("%d %d %d",&year,&month,&day);
   for(i=0;i<month-1;i++)//加month之前的所有天数
  sum+=date[i];
   sum+=day;//加当天月份的天数
   printf("它是%d年中的第%d天\n",year,sum);
   return 0;
}


猜你喜欢

转载自blog.csdn.net/ling_cmd/article/details/78296696