给定一个日期,输出这个日期是该年的第几天 C语言编程题

#include<stdio.h>
main(){
int year,month,day,i=0;
printf("please input year month day:\n");
scanf("%d %d %d",&year,&month,&day);
switch(month-1) {
case 11: i=i+30;
case 10: i=i+31;
case 9: i=i+30;
case 8: i=i+31;
case 7: i=i+31;
case 6: i=i+30;
case 5: i=i+31;
case 4: i=i+30;
case 3: i=i+31;
case 2: if((year%400==0)||(year%4==0)&&(year%100!=0)) i=i+29;
else i=i+28;
case 1: i=i+31; }
i=i+day;
printf("i=%d\n",i);
getch();}

#include<stdio.h>
int main()
{
int sum=0;
int i;
int month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int yeal,mon,day;
printf("输入日期,格式为‘yeal,month,day’,如2012,11,23\n");
scanf("%d,%d,%d",&yeal,&mon,&day);
if((yeal%400==0)||(yeal%4==0)&&(yeal%100!=0))
month[1]=29;//若是闰年,则二月有29天。
for(i=0;i<mon-1;i++)
sum=sum+month[i];
sum=sum+day;
printf("共有%d天",sum);
return 0;
}
温馨提示:答案为网友推荐,仅供参考
相似回答
大家正在搜