大家看看这个程序有什么问题?输入日期计算是一年的第几天?

来源:百度知道 编辑:UC知道 时间:2024/06/23 01:18:35
#include"stdio.h"
struct
{
int month;int day;int year;
}date;
void main()
{
int i=0;
int days=0;
printf("Input year,month,days:");
scanf("%d,%d,%d",&date.year,&date.month,&date.day);
for(i=1;i<date.month;i++)
{if(i=1||3||5||7||8||10) days+=31;
else if(i=4||6||9||11) days+=30;
else if(i=(date.year%4==0)&&(date.year%100!=0)||(date.year%400==0)) days+=29;
else days+=28;}
days+=date.day;
printf("%d %d %d is this year of %d th days.",date.year,date.month,date.day);
getch();
}

头一次见到这麼写的
{if(i=1||3||5||7||8||10) days+=31;
else if(i=4||6||9||11) days+=30;

if( i == 1
|| i ==3
|| i== 5)

这样

if(i==1||i==3||i==5||i==7||i==8||i==10) days+=31;
else if(i==4||i==6||i==9||i==11) days+=30;
else if((date.year%4==0)&&(date.year%100!=0)||(date.year%400==0)) days+=29;
或者直接改成
switch(i) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
days+=31;
break;
case 4:
case 6:
case 9:
case 11:
days+=30;
break;
default:
if((date.year%4==0)&&(date.year%100!=0)||(date.year%400==0)) days+=29;
else days+=28;
break;
}