C语言,输入年月日,判断是这一年的第几天?
11个回答
2012-12-24
展开全部
#include <stdio.h>
int main(void)
{
int year,month,day,sum,leap;
printf("请输入年月日,每个数据以空格相隔:");
scanf("%d %d %d", &year, &month, &day);
switch(month)
{
case 1:sum = 0;
break;
case 2:sum = 31;
break;
case 3:sum = 59;
break;
case 4:sum = 90;
break;
case 5:sum = 120;
break;
case 6:sum = 151;
break;
case 7:sum = 181;
break;
case 8:sum = 212;
break;
case 9:sum = 243;
break;
case 10:sum = 273;
break;
case 11:sum = 304;
break;
case 12:sum = 334;
break;
default:printf("月份数输入错误!\n");
return -1;
}
sum += day;
if (year%400==0 || (year%100!=0 && year%4==0))
leap = 1;
else
leap = 0;
if (1==leap && month>2)
sum++;
printf("这一天是这一年的第%d天\n", sum);
return 0;
}
int main(void)
{
int year,month,day,sum,leap;
printf("请输入年月日,每个数据以空格相隔:");
scanf("%d %d %d", &year, &month, &day);
switch(month)
{
case 1:sum = 0;
break;
case 2:sum = 31;
break;
case 3:sum = 59;
break;
case 4:sum = 90;
break;
case 5:sum = 120;
break;
case 6:sum = 151;
break;
case 7:sum = 181;
break;
case 8:sum = 212;
break;
case 9:sum = 243;
break;
case 10:sum = 273;
break;
case 11:sum = 304;
break;
case 12:sum = 334;
break;
default:printf("月份数输入错误!\n");
return -1;
}
sum += day;
if (year%400==0 || (year%100!=0 && year%4==0))
leap = 1;
else
leap = 0;
if (1==leap && month>2)
sum++;
printf("这一天是这一年的第%d天\n", sum);
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
main()
{
int year,moth,day;;
int mo[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int d,i;
scnaf("%d %d %d",&year,&moth,&day);
d=day;
if(闰年判断)
mo[1]=29;
for(i=0;i<moth-1;i++)
d+=mo[i];
printf("%d",d);
}
{
int year,moth,day;;
int mo[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int d,i;
scnaf("%d %d %d",&year,&moth,&day);
d=day;
if(闰年判断)
mo[1]=29;
for(i=0;i<moth-1;i++)
d+=mo[i];
printf("%d",d);
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
追问 case 1:sum=0;break; default:printf("data error");break; } sum=sum day; if(year@0==0||(year%4==0&&year 0!=0)) leap=1; else leap=0; if(leap==1&&month>2) sum ; printf("%d",sum); }
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
if(year%00==0
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询