用C語言來實現_輸入一個日期(年月日),計算是這一年中的第幾天
阿新 • • 發佈:2019-01-01
1.環境:
2.程式碼:
/*
*wuxiuwen*input date, the date of this year is calculated which day.
*輸入一個日期(年月日),計算是這一年中的第幾天
*/
#include<stdio.h>
int dm(int year,int month, int day)
{
int flag=0;
if((year%4==0 && year%100!=0) || (year%400==100))flag = 1;
else flag =0;
int a=0;
switch(month-1)
{
case 11 :a+=30;
case 10 :a+=31;
case 9 :a+=30;
case 8 :a+=31;
case 7 :a+=31;
case 6 :a+=30;
case 5 :a+=31;
case 4 :a+=30;
case 3 :a+=31;
case 2 :a+=28+flag;
case 1 :a+=31;break;
default :printf("Please input others\n");
}
a +=day;
printf("THIS IS THE %d DAY OF %d.\n",a,year);
}
int main()
{
int day,month,year;
printf("please input the date(year.month.day):\n");
scanf("%d.%d.%d",&year,&month,&day);
dm(year,month,day);
return 0;
}
3.說明: