简单的日期转天数,初学者求大虾帮忙。
#include<stdio.h>
int main()
{
int two,year,month,day,date,a,m;
int m[11]={31,two,31,30,31,30,31,31,30,31,30};
if (year/400==0||year%4==0&&year%100!=0)
two=29;
else
two=28;
printf("请输入某年某月某日");
scanf("%d,%d,%d",&year,&month,&day);
switch(month)
{case 1:
date=day;
case 2:
date=m[0]+day;
case 3:
date=m[0]+m[1]+day;
case 4:
date=m[1]+m[2]+m[0]+day;
case 5:
date=m[1]+m[2]+m[3]+m[0]+day;
case 6:
date=m[1]+m[2]+m[3]+m[4]+m[0]+day;
case 7:
date=m[1]+m[2]+m[3]+m[4]+m[5]+m[0]+day;
case 8:
date=m[1]+m[2]+m[3]+m[4]+m[5]+m[6]+m[0]+day;
case 9:
date=m[1]+m[2]+m[3]+m[4]+m[5]+m[6]+m[7]+m[0]+day;
case 10:
date=m[1]+m[2]+m[3]+m[4]+m[5]+m[6]+m[7]+m[8]+m[0]+day;
case 11:
date=m[1]+m[2]+m[3]+m[4]+m[5]+m[6]+m[7]+m[8]+m[9]+m[0]+day;
case 12:
date=m[1]+m[2]+m[3]+m[4]+m[5]+m[6]+m[7]+m[8]+m[9]+m[10]+m[0]+day;
}
printf("这是%d年第%d天",year,date);
return 0;
}
你定义了一个数组叫m,还定义了一个int类型变量也叫m
判断闰年应该是year%400==0不是 year/400==0
你所有的case结束要加 break;
int m[11]={31,two,31,30,31,30,31,31,30,31,30};这样不行啊,改为
int m[11]={31,28,31,30,31,30,31,31,30,31,30};
if (year%400==0||year%4==0&&year%100!=0)
m[1]=29;