/* 判斷某一日期是當(dāng)年的第幾天*/在C語(yǔ)言的程序中如何編寫?
#include"stdio.h"
void main()
{
int n,year,month,day,month_day_sum=0,sum,
month_day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
printf("請(qǐng)輸入\"年月日\(chéng)"\n");
scanf("%d%d%d",&year,&month,&day);
if(year%100!=0&&year%4==0||year%400==0) month_day[2]=29;
if(day>31||day<1||month>12||month<1) printf("錯(cuò)誤");
else
{
for(n=1;n<month;n++) month_day_sum+=month_day[n];
sum=month_day_sum+day;
printf("是%d年的第%d天\n",year,sum);
}
}
點(diǎn)擊加載更多評(píng)論>>